We have an xPage which contains a comboBox control. That comboBox has 10 selectItems, numbered 1 through 10.
We would like to set the initially selected option for the comboBox based on a sessionScope variable.
Normally, we would simply add (selected=“selected”) to one of the options, and that would do the trick. However, using the xPage control and associated properties, I am unable to programmatically set the default option selected in the comboBox.
I suppose I could generate the necessary HTML via a Computed Field control, but I’d like to hook server-based jscript activity to the onChange event.
I’d also like to find out if there is a “best practice” method of achieving this, so any/all suggestions would certainly be appreciated.
All you need to do is bind the combobox to your sessionScope variable (look at the Data tab). If you’ve done that and your value isn’t showing as being selected, then you likely have a problem with your formula that’s populating the items, or your sessionScope variable doesn’t contain what you think it does. The combobox is for a single-value item only.
However, when I tested that method, the comboboxes became “read only” with the assigned value (no more drop-down options).
Perhaps I tested it wrong?
Rather than bind the control to a sessionScope variable, I simply placed the string “4” in Javascript. That should have worked, since the variable will be returning a similar string.
However, the results would not let me review the options and select an alternate.
What I am trying to achieve is have the comboboxes default to the previously selected number, but allow the user to change that number prior to submitting the information.
Subject: Hmm… What does your source code look like?
I just tried binding a combobox to a sessionScope variable and it is editable and changeable. This is what my source looks like for the combobox & in the beforePageLoad event I set the sessionScope.myColour = document1.getItemValueString(“Colour”):<xp:comboBox id=“comboBox3”
... renders the text value where the field is, but it's not editable.
Perhaps I should be returning something other than a string when I calculate the default value?
I'm pretty sure sessionScope variables are stored in a hashmap, but haven't dug that far down yet.
BTW:- I've been right thru Declan's "Learning XPages" series. It was an excellent kickstart. However, there's ever so much more to learn!!
Cheers!
T.