Xpages: Blank value for default on combo box

Hi,

I have a combo box in XPages for which I would like to have the default value as null and allow this to be validated.

I have tried adding a value with:

return “”

and

return null

However, these values are ignored as the first ‘real’ value in the list is displayed instead. Not what I want.

The only way I can get around the problem at the moment is to create a value and default value of:

return " " ← space between the speech marks

Looks great and works like a dream. The problem is now that I would like to, at times, validate this field with server-side validation. As there is a ‘value’ in the field it considers it complete.

Am I missing something obvious? Has anyone got any ideas how to get around this?

Thanks.

Ian

Subject: Would this work for you?

<xp:comboBox id=“comboBox1” value=“#{requestScope.t01}”>

xp:this.validators

<xp:validateRequired

message=“Please select an option from the combo box”>

</xp:validateRequired>

</xp:this.validators>

<xp:selectItem itemLabel=“Pick something” itemValue=“”></xp:selectItem>

<xp:selectItem itemLabel=“AAA” itemValue=“AAA”></xp:selectItem>

<xp:selectItem itemLabel=“BBB” itemValue=“BBB”></xp:selectItem>

<xp:selectItem itemLabel=“CCC” itemValue=“CCC”></xp:selectItem>

</xp:comboBox>

<xp:message id=“message1” for=“comboBox1”></xp:message>

xp:br</xp:br>

<xp:button id=“button1” value=“Submit”>

<xp:eventHandler event=“onclick” submit=“true”

refreshMode=“complete” immediate=“false” save=“true”>

</xp:eventHandler>

</xp:button>

http://www.bleedyellow.com/blogs/XPagesStuff/entry/combobox_with_validation?lang=en

Subject: Thanks… But

I see this post and now understand the difference between the ‘label’ and the 'value. However, when the source code is changed to return a value of “” that vanishes when you click in the ‘value’ box in the UI.

Any ideas? Apart from that, it’s just a case of don’t touch it after you’ve done it but not ideal!

Subject: Fixed

Add a computed field to your values as follows:

return “”

In the default value, add:

return null

Validation will work and you will get a blank field to start with.

Subject: yes the UI regenerates the value…

…and it looks to be working as designed as DD expects that if you go into the source you must be an advanced user. However, maybe this warrants a bug report to not re-generate the null in the source.

p.