To See Or Not To See? That Is The Question.
XPages are now becoming the way that developers
are writing and extending apps to the Web and beyond. One of the (many)
quirks I've found, which cost me several hours, was the ‘visibility’
property for each control.
Generally, there are two reasons for using this property on controls. The first is to show or hide a control, depending on who is logged in and using the application. For example; an approval button may only show up for managers, not general users.
This can be achieved by entering something similar to the following code in the ‘computed’ value for the visibility property:
var roles:Array = database.queryAccessRoles(session.getEffectiveUserNAme());
@IsMember(“ole, roles);
The other main reason is to hide or show a control, depending on the input from another control. For example; a text box displaying when a option for a combo box is selected, or if a check box is checked.
In this case, I would create a comb box with some options, such as ‘approve’, ‘approve with comments’, ‘deny’ and ‘deny with comments’, and uncheck the visibility box of the text box. Then, I'd write some code in the event handler for the combo box (or check box, or button, or whatever) to display the text box control when appropriate.
However… this does not work! The text box never appears on the page (no matter how many times I select different options ;-))
After thinking this was a problem with my event handler code - I tried to set several properties, visible=true, rendered=true, etc.- I was about to give in and try a different method. Instead, I decided to look at the source code for the control and found the following:
<xp:inputText id=”inputText” rendered=”false”></xp: inputText >
Aha…. What’s this??? “rendered=false”!!!! The light bulb above my head went on!
‘Rendered’ is not the same as ‘visible’! No matter what you do, the web page will never be able to show this control, as it is never rendered at run time.
Metaphorically speaking: If I don't see a car coming while I'm crossing the street and it hits me, I get killed. Although the car is not visible, it's still there, and it still hits me - I just didn't see it.
For Xpages to dynamically display controls, or contents within control containers, the web page has to use Javascript in the event handler and round trip to the server. Therefore, the following code entered in the onchange event of the combo box is one way to achieve this:
var cBox:javax.faces.component.UIComponent = getComponent("comboBox");
var option= cBox.getValue();
var textBox:javax.faces.component.UIComponent = getComponent("inputText");
if ((option == "approve with comments") || (option == "deny with comments"))
textBox.setRendered(true);
else
textBox.setRendered(false);
For the scenario in which you require hidden fields, there is a control that is, for some ironic reason, hidden. You can access it in the Preferences menu of Designer 8.5.1, and you can bind this to any field in your Notes documents, just as you would with other types of controls.
Generally, there are two reasons for using this property on controls. The first is to show or hide a control, depending on who is logged in and using the application. For example; an approval button may only show up for managers, not general users.
This can be achieved by entering something similar to the following code in the ‘computed’ value for the visibility property:
var roles:Array = database.queryAccessRoles(session.getEffectiveUserNAme());
@IsMember(“ole, roles);
The other main reason is to hide or show a control, depending on the input from another control. For example; a text box displaying when a option for a combo box is selected, or if a check box is checked.
In this case, I would create a comb box with some options, such as ‘approve’, ‘approve with comments’, ‘deny’ and ‘deny with comments’, and uncheck the visibility box of the text box. Then, I'd write some code in the event handler for the combo box (or check box, or button, or whatever) to display the text box control when appropriate.
However… this does not work! The text box never appears on the page (no matter how many times I select different options ;-))
After thinking this was a problem with my event handler code - I tried to set several properties, visible=true, rendered=true, etc.- I was about to give in and try a different method. Instead, I decided to look at the source code for the control and found the following:
<xp:inputText id=”inputText” rendered=”false”></xp: inputText >
Aha…. What’s this??? “rendered=false”!!!! The light bulb above my head went on!
‘Rendered’ is not the same as ‘visible’! No matter what you do, the web page will never be able to show this control, as it is never rendered at run time.
Metaphorically speaking: If I don't see a car coming while I'm crossing the street and it hits me, I get killed. Although the car is not visible, it's still there, and it still hits me - I just didn't see it.
For Xpages to dynamically display controls, or contents within control containers, the web page has to use Javascript in the event handler and round trip to the server. Therefore, the following code entered in the onchange event of the combo box is one way to achieve this:
var cBox:javax.faces.component.UIComponent = getComponent("comboBox");
var option= cBox.getValue();
var textBox:javax.faces.component.UIComponent = getComponent("inputText");
if ((option == "approve with comments") || (option == "deny with comments"))
textBox.setRendered(true);
else
textBox.setRendered(false);
For the scenario in which you require hidden fields, there is a control that is, for some ironic reason, hidden. You can access it in the Preferences menu of Designer 8.5.1, and you can bind this to any field in your Notes documents, just as you would with other types of controls.
Category
Comments
Posted by Tim Tripcony At 10:34:45 PM On 08/05/2010 | - Website - |
Posted by Nathan T. Freeman At 12:06:10 AM On 08/06/2010 | - Website - |
I guess my point was that the only difference between an "Edit Box" control and a "Hidden Input" control is that, when adding the latter, Designer sets a default value for the "rendered" attribute... the tag name (and, therefore, the Java class instantiated when the control is encoded) is the same for both.
Hence, you can make an "Edit Box" a "Hidden Input" by simply deselecting "Visible" in the properties pane... or, conversely, you can change a "Hidden Input" to a conditionally-rendered "Edit Box" by changing that attribute to be dynamically computed instead of leaving the static default value. As far as the XPages runtime is concerned, the two are exactly the same component.
Posted by Tim Tripcony At 01:44:04 PM On 08/06/2010 | - Website - |
Posted by Craig Wiseman At 10:56:39 AM On 08/07/2010 | - Website - |
Posted by RIch At 04:52:03 PM On 08/11/2010 | - Website - |
Posted by stamp price 2012 At 03:06:39 PM On 09/30/2011 | - Website - |
Posted by mens hairstyles 2012 medium At 12:39:34 AM On 10/01/2011 | - Website - |
Posted by bbq ideas for a crowd At 03:05:21 AM On 10/07/2011 | - Website - |
Posted by Demonstration speech ideas At 05:48:36 AM On 10/13/2011 | - Website - |
Posted by Trendfrisuren 2012 At 02:49:59 AM On 10/25/2011 | - Website - |
Posted by june 2012 calendar printable At 01:26:53 PM On 10/26/2011 | - Website - |
Posted by Buy Supra Shoes UK At 06:25:15 AM On 11/29/2011 | - Website - |
Posted by ugg boots sale uk At 07:33:34 PM On 12/25/2011 | - Website - |
Posted by At 08:35:37 PM On 12/25/2011 | - Website - |