Show TOC Start of Content Area

Procedure documentation Checking the Permission in the Web Dynpro Client Locate the document in its SAP Library structure

Use

The next step is to adjust the Web Dynpro screen according to the user’s authorizations. If the user does not have the authorization to maintain reservations, you will set the corresponding fields to read only and hide the buttons for creating or displaying reservations. For this purpose, you will call the hasPermission()method and adjust the screen accordingly.

Necessary Imports

The table below shows the packages and classes that are needed for processing the permission check and adjusting the Web Dynpro screen.

Packages and Classes

Package or Class

Description

com.sap.tc.webdynpro.clientserver.
uielib.standard.api.
IWDAbstractInputField

Interface to the input field properties

com.sap.tc.webdynpro.clientserver.
uielib.standard.api.
IWDAbstractButton

Interface to the button properties

com.sap.tc.webdynpro.progmodel.api.WDVisibility

Class specifying the visibility property of UI elements

com.sap.tc.webdynpro.services.sal.
um.api.IWDClientUser

Interface to the Web Dynpro client user

com.sap.tc.webdynpro.services.sal.
um.api.WDClientUser

Provides the methods for accessing the user properties

com.sap.tc.webdynpro.services.sal.
um.api.WDUMException

Exceptions for user management

Input Fields to Set to Read-Only

Each input field has a property that indicates whether the field is read-only or ready for input. To access this property, you must know each field’s identifier. See the tables below.

Input Field Identifiers

Field

Identifier

Pickup Date

dateFromString

Return Date

dateToString

Pickup Location

pickupLocation

Dropoff Location

dropoffLocation

Vehicle Type

vehicleTypeId

Button Identifiers

Button

Identifier

Rent a Car

Rent

Display all Bookings

DisplayAll

Prerequisites

This graphic is explained in the accompanying textThis graphic is explained in the accompanying text

The Web Dynpro perspective is displayed in the SAP NetWeaver Developer Studio.

This graphic is explained in the accompanying textThis graphic is explained in the accompanying text

The Web Dynpro car rental project, TutWD_CarRental, is displayed in the Web Dynpro Explorer.

Procedure

...

       1.      Choose the Web Dynpro Explorer.

       2.      Expand TutWD_CarRental ® Web Dynpro ® Web Dynpro Components ®CarRentalComp ® Views.

       3.      Open the FormView by selecting it with a double-click.

The information for the initial form view appears in the right pane.

       4.      Choose the Implementation tab page.

       5.      Insert the necessary includes as shown below.

import com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDAbstractButton;
import com.sap.tc.webdynpro.progmodel.api.WDVisibility;
import com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDAbstractInputField;
import com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser;
import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;
import com.sap.tc.webdynpro.services.sal.um.api.WDUMException;
import com.sap.tut.wd.carrental.wdp.IPrivateFormView;

       6.      Adjust the wdDoModifyView() method. Obtain the user’s ID and insert the hasPermission()check. If the user does not have the permission to create reservations, then set the read-only property for each of the input fields to true. See the code sample below:

public static void wdDoModifyView(IPrivateFormView wdThis, IPrivateFormView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
   

   try {

      IWDClientUser user = WDClientUser.getCurrentUser();
      IWDAbstractInputField fi;
      IWDAbstractButton button; 
  
if (user.hasPermission(new WDCarRentalPermission("WDmaintain")) == false) {
        
         fi = (IWDAbstractInputField)view.getElement(
"dateFromString");
         fi.setReadOnly(true);
        
         fi = (IWDAbstractInputField)view.getElement(
"dateToString");
         fi.setReadOnly(true);

         fi = (IWDAbstractInputField)view.getElement(
"pickupLocation");
         fi.setReadOnly(true);
  
         fi = (IWDAbstractInputField)view.getElement(
"dropoffLocation");
         fi.setReadOnly(true);

         fi = (IWDAbstractInputField)view.getElement(
"vehicleTypeId");
         fi.setReadOnly(true);
        
         button = (IWDAbstractButton)view.getElement(
"Rent");
         button.setVisible(WDVisibility.NONE);

         button = (IWDAbstractButton)view.getElement(
"DisplayAll");
         button.setVisible(WDVisibility.NONE);
      }
  
   }
catch (WDUMException e) {
      e.printStackTrace();
   }
    //@@end
  }

       7.      Save the metadata.

Result

If the user does not have the permission to maintain reservations, then the corresponding fields are set to read only and the buttons are not visible.

Next Step:

Rebuilding and Redeploying the Project

 

End of Content Area