!--a11y-->
Checking the Permission in the Web Dynpro
Client 
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.
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. |
Interface to the input field properties |
com.sap.tc.webdynpro.clientserver. |
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. |
Interface to the Web Dynpro client user |
com.sap.tc.webdynpro.services.sal. |
Provides the methods for accessing the user properties |
com.sap.tc.webdynpro.services.sal. |
Exceptions for user management |
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 |
|
|
The Web Dynpro perspective is displayed in the SAP NetWeaver Developer Studio. |
|
|
The Web Dynpro car rental project, TutWD_CarRental, is displayed in the Web Dynpro Explorer. |
...
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; |
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)
IWDClientUser user = WDClientUser.getCurrentUser(); |
7. Save the metadata.
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.
Rebuilding and Redeploying the Project