cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling/ Disabling UI Elements using Web Dynpr Java

Former Member
0 Kudos

Hi Experts,

I have certain UI Elements in the view layout, and i want to disable it based on conditions. I want only certain users to be able to edit the fields and the other set of users should only be able to view the data in the UI Elements and not EDIT. can any one hlep me out please...

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

UI Elements has a property called "readOnly."

What you need to do is manipulate this programmatically by binding this property to a value attribute of type boolean like "isNameFieldReadOnly". Say if a given condition applies, just set this one to 'true' to make it read-only. Some elements also have a an 'enabled' property (i.e. buttons) you can also manipulate it the same way.

For example:

boolean validCondition = true;

//if condition applies, set the context attribute value
if(validCondition){
  wdContext.currentContextElement.setIsNameFieldReadOnly(true); //the UI element property read-only is set to true
}

Goodluck!

Regards,

Jan

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi All,

Thanks for the reply. I got the answer.

Thanks once again.

Former Member
0 Kudos

And "the answer" is?

Armin

Former Member
0 Kudos

drum roll

String Theory?

Former Member
0 Kudos

Hi,

I forgot to mention the Enabled Property, which is also there and can be used the same as the Read only property, with a boolean VA.

Thanks,

Guillermo

Former Member
0 Kudos

Hi,

as someone said before, the UI elements have the read only property. As default it comes as false, so it is editable.

What you can do is to create some Value Attribute of boolean type, and assign this Value Attribute to the read only property for the UI Element.

Whenever you want to allow on some condition that it should be readonly or not, you can change the value of the Value Attribute.

Hope this helps,

Guillermo

Former Member
0 Kudos

If your application runs inside the NW Portal you can use role-based personalization for restricting funcitonality based on the role of the current user.

Armin

gill367
Active Contributor
0 Kudos

HI satish,

well you can do this by binding the readonly or enable property of the input field to a context attribute of boolean type and then checking in the wddoinit method for the user authentication. If the user is authenticated then you can set the attribute to true.

Authentication can be done by providing all the users with a role (say enable) for which you want the fields to be enabled and you can check for the roles of the logged in user and if that particular role is pesent there you can enable the fields.

The following is the code that you can write in your Wddoinit method for the work.

String strUserName = null;
	boolean rolestrflg = true;
   try {
		 IWDClientUser clusr = WDClientUser.getCurrentUser();
	       IUser sapUser = clusr.getSAPUser();
	       
	if (sapUser != null) {
					IUserAccount[] acct = sapUser.getUserAccounts();
		if (acct[0] != null) {
							strUserName = acct[0].getDisplayName();
						 Iterator rolesit = sapUser.getRoles(true);
			IRoleFactory rfact = UMFactory.getRoleFactory();
			while (rolesit.hasNext()&& rolestrflg) {
									String roleName = (String) rolesit.next();

									IRole role = rfact.getRole(roleName);
									
									
		                if(role.getUniqueName().equalsIgnoreCase("Enable")) // suppose the role for enabling the fields is Enable
		                {
		                	wdContext.currentContextElement().setContrl(true);
		                	rolestrflg = false;
		                }
		                else
		                {
			wdContext.currentContextElement().setContrl(false);
		                }
		                
			}
							
		}
	}
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

i hope this will solve your problem

regards,

Sarbjeet

former_member205363
Contributor
0 Kudos

Hi,

You can get the user details in

String userId = "";

IWDClientUser wdUser = null;

IUser user = null;

IUserAccount[] acct = null;

try {

wdUser = WDClientUser.getCurrentUser();

user = wdUser.getSAPUser();

if (user != null) {

acct = user.getUserAccounts();

userId = acct[0].getLogonUid();

if (userId != null) {

wdThis.wdGetContext().currentContextElement().setCurrentCustomer(userId.toUpperCase());

return userId.toUpperCase();

} else {

wdComponentAPI.getMessageManager().reportWarning(" Invalid user1");

}

} else {

wdComponentAPI.getMessageManager().reportWarning(" Invalid user2");

}

} catch (Exception e) {

wdComponentAPI.getMessageManager().reportWarning(" Invalid user3" + e.getMessage());

}

return "";

Besed on the login user you can apply the readOnly property to the UI Elements.

Regards,

Lakshmi Prasad.