« Which is Your Favorite Notes Release? | Main| Debugging Java (and XPages) in DDE »

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.

visible.png

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.

hidden_input.png

Category

Comments

1 - Richard, the "rendered" attribute does map to the "visible" setting in the Designer GUI. If you set this attribute to be computed on the inputText control, and reference the value of the comboBox in that computation, as long as you choose "compute dynamically" instead of "compute on page load" (in the source, this will be indicated by a # for dynamic or $ for compute-once), then the control will display once the comboBox has the desired value.

2 - @Tim - Not if the comboBox refresh event only does a partial that doesn't include the inputText. Isn't he going to have to specify the target id for the onChange event of the combo to a container that includes the input?

3 - @Nathan - yes, the onChange event would need to target a container of the inputText... or the inputText itself. So one could argue that it makes more sense to toggle the visibility directly within the event code. On the other hand, other events could alter the value of the comboBox such that the inputText should display, but because the onChange event itself was never fired, the input would still not render. Keeping the computation local to the impacted control is likely to be more reliable and maintainable.

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.

4 - This discussion (to me) indicates that while xPages is very cool, functional technology, it is very much not RAD.

5 - @Tim - This is how I have been using edit boxes in the form of hidden data in the past (as well as scoped variables obviously). However, I think it is better practice to use the hidden 'hidden input' field when appropriate - I guess it comes down to intent and future maintenance of the app.

6 - Most people, when they criticize, whether they like it or hate it, they're talking about product. That's not art, that's the result of art. Art, to whatever degree we can get a handle on (I'm not sure that we really can) is a process. It begins in the heart and the mind with the eyes and hands.

7 - Most people, when they criticize, whether they like it or hate it, they're talking about product. That's not art, that's the result of art. Art, to whatever degree we can get a handle on (I'm not sure that we really can) is a process. It begins in the heart and the mind with the eyes and hands.

8 - Keep away from people who try to belittle your ambitions. Small people always do that, but the really great make you feel that you, too, can become great.

9 - The Constitution gives every American the inalienable right to make a damn fool of himself.

10 - If you would be a real seeker after truth, it is necessary that at least once in your life you doubt, as far as possible, all things.

11 - Better to remain silent and be thought a fool than to speak out and remove all doubt.

12 - The Mens Supra Muska Skytop Shoes at its exterior using the snap closure. An adjustable belt for the supra uk has two benefits.

13 - WT-The Cheap ugg Boots is well-known brands, and also the world's most famous ugg boots brand. Sold in the UK market is the United States, Genuine Ugg boots, and are made in China. All sheep wool of fine workmanship, { Link } ,even in summer wear Ugg man boots will not feel hot. Sand and chestnut color is the most popular color, mid-counter sale of stock. { Link }

14 -

Post A Comment

Feeds

Custom Button Custom Button

Category Cloud

Disclaimer

The views expressed by the authors on this blog do not necessarily reflect the views of Teamstudio, those who link to this blog, or even the author’s mother, father, sister, brother, uncle, aunt, grandparents, cousins, step relations, any other blood relative - and sometimes not even the author himself or herself.

Comments on this website are the sole responsibility of their writers and it is assumed those writers will take full responsibility, liability, and blame for any libel or litigation that results from something written in, or as a direct result of something written in, a comment. The accuracy, completeness, veracity, honesty, exactitude, factuality and politeness of comments are not guaranteed. Oh, how they are SO not guaranteed.
en-us,en;q=0.5OFFCCBot/1.0 (+http://www.commoncrawl.org/bot.html)38.107.179.211www.getthemostfromnotes.comHTTP/1.180Lotus-Domino/tsblog.nsf/d6plinks/KFRA-882SK8