Learning XPages Part 32 : Using Roles To Make Fields Editable
Tags : Lotus Domino XPages Roles
Bookmark :
Now that we can switch our page into Edit Mode you'll see that all of the fields are editable. In most applications you may not want this so we can disable the ability to edit certain fields. Start by opening the content_Person custom control again.
Lets disable a couple of the fields that we don't want the end user changing. Select the 'FirstName' field and look at the properties. In the 'Edit Box' properties you will see a 'Read Only' tickbox. Turning this on will make the field uneditable. Nice and simple for this particular field.
You may also notice that the 'Read-Only' tickbox has a diamond beside it. You can use this to create a computed result to determine if the field should be read only or not.
Lets say that we don't want the end user editing their Job Title but we do want somebody with the 'PhonebookEditor' role in the ACL to be able to update peoples job titles. First of all click on the 'JobTitle' field in the design and then in the properties click the diamond for the 'Read-Only' flag and select compute value. In the script editor that appears we need to enter in the code to see if the currently logged in person has the role or not. Here's the code I'm using :
var s1 = context.getUser().getRoles();
var s2 = "{PhonebookEditor}";
if(@Contains(s1, s2) == @True())
return false;
else
return true;
NOTE : Replace curly brackets with square brackets in the above code.
This very simple code could be reduced in size but I've left it expanded so you can see how it is working, I am setting up two variables and then doing an @contains to see if the role exists inside the current users .getRoles value. This would be very similar to how you would do it on a form in traditional notes client development.
In the next part I'll add some validation to the fields that can be edited so make sure the person enters in valid data.
Bookmark :
Now that we can switch our page into Edit Mode you'll see that all of the fields are editable. In most applications you may not want this so we can disable the ability to edit certain fields. Start by opening the content_Person custom control again.
Lets disable a couple of the fields that we don't want the end user changing. Select the 'FirstName' field and look at the properties. In the 'Edit Box' properties you will see a 'Read Only' tickbox. Turning this on will make the field uneditable. Nice and simple for this particular field.
You may also notice that the 'Read-Only' tickbox has a diamond beside it. You can use this to create a computed result to determine if the field should be read only or not.
Lets say that we don't want the end user editing their Job Title but we do want somebody with the 'PhonebookEditor' role in the ACL to be able to update peoples job titles. First of all click on the 'JobTitle' field in the design and then in the properties click the diamond for the 'Read-Only' flag and select compute value. In the script editor that appears we need to enter in the code to see if the currently logged in person has the role or not. Here's the code I'm using :
var s1 = context.getUser().getRoles();
var s2 = "{PhonebookEditor}";
if(@Contains(s1, s2) == @True())
return false;
else
return true;
NOTE : Replace curly brackets with square brackets in the above code.
This very simple code could be reduced in size but I've left it expanded so you can see how it is working, I am setting up two variables and then doing an @contains to see if the role exists inside the current users .getRoles value. This would be very similar to how you would do it on a form in traditional notes client development.
In the next part I'll add some validation to the fields that can be edited so make sure the person enters in valid data.
Comments
Sorry for the interruption. Please continue...
Posted by Kevin Pettitt At 05:07:58 PM On 03/04/2009 | - Website - |
There's many @functions like that -- seemingly simple to implement, but they weren't.
Posted by Erik Brooks At 05:33:27 PM On 03/04/2009 | - Website - |
Posted by Devin Olson At 05:59:11 PM On 04/18/2009 | - Website - |