Is there a way to set the inital "selected" value of a combo box on an xpage?

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.

Cheers!

T.

Subject: Combobox binding

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.

Subject: Not exactly what I was looking for

Thanks very much for your reply Judy!

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.

Cheers!

T.

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”

				value="#{sessionScope.myColour}">

				<xp:selectItems>

					<xp:this.value><![CDATA[${javascript:@DbLookup( @DbName(),"LU_Keyword", "Colour", 2 );}]]></xp:this.value>

				</xp:selectItems>

			</xp:comboBox>

I don’t mean to imply anything, but are you sure you’re in Edit mode on the document and have Author access to the document?

One thing I use a lot for debugging scope variables are a set of custom controls that Declan Lynch developed (oops, wrong link – they’re actually here: http://www.qtzar.com/blogs/qtzar.nsf/blog.xsp?entry=DSLH-7S7JUY&SessionID=CNFLZXUWFB) – you just pop them into you XPage and you can see what’s up with all your scope variables.

But it’s worth going through his “Learning XPages” series: http://www.qtzar.com/blogs/qtzar.nsf/Document.xsp?documentId=A97DB47B9BEDB9868525756F005BC3C3&action=openDocument&SessionID=COLQT6M12O)

Subject: That is strange, but you’re right…

Thanks for sticking with this Judy.

You’re correct, if I apply the contents of a sessionScope variable to the value of the comboBox control, it works exactly as you said.

However, I am extracting a value from that sessionScope variable, and returning a string. That must be the difference between the two methods.

If I use your method…

sessionScope.testChoice = “4”;

<xp:comboBox id=“comboBox3” value=“#{sessionScope.testChoice}”>

… it all looks good. However, using my method…

sessionScope.testChoice = “4@10.00”;

<xp:comboBox id=“comboBox3”>

xp:this.value

... 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.