Hi folks. We could use some assistance with a nagging problem – combobox choices with aliases don’t seem to work well on a XPage (we’re using 8.5.2).
Our combobox gets its values from a keyword lookup. The list that comes back has aliases, like “Male|M”. We want to use the “Male” value for display, and save the “M” to the document on submit.
The choice list shows the display values (like “Male”). When the Xpage is submitted, the value that is POSTed (Firebug to the rescue!) is “Male”, rather than “M”. In some configurations, the page will refresh, clear the field and not save the document.
In an attempt to force the values to convert, we created a custom converter for the field - here’s the code from the server side javascript library:
/*
FOO.UI.Utilities.getPicklist.choices returns [{ “display”:”Male”,”value”:”M”}, { “display”:”Female”,”value”:”F”}
FOO.UI.Utilities.getPicklist.choices returns [“Male|M”,”Female|F”]
*/
FOO.UI.Converters = function(){
return {
picklist: {
getAsObject: function( valueSubmitted , choices){ // submitted to stored
try {
for( var i = 0; i < choices.length; i++ ){
if (choices[i].display == valueSubmitted) {
return choices[i].value;
}
}
return valueSubmitted;
} catch( e ){ /* Exception handling */
}
},
getAsString: function( valueStored, choices){ // stored to display
try {
for( var i = 0; i < choices.length; i++ ){
if (choices[i].value == valueStored) {
return choices[i].display;
}
}
return valueStored;
} catch( e ){ /* Exception handling */ }
}
}
}
}();
Here’s the source code on the Xpage:
<xp:comboBox id=“comboBox1” value=“#{document1.regsex}”>
<xp:this.converter>
<xp:customConverter>
<xp:this.getAsObject>
<![CDATA[#{javascript:
return FOO.UI.Converters.picklist.getAsObject( value, FOO.UI.Utilities.getPicklist("Gender").choices);}]]
>
</xp:this.getAsObject>
<xp:this.getAsString>
<![CDATA[#{javascript:
return FOO.UI.Converters.picklist.getAsString( value, FOO.UI.Utilities.getPicklist("Gender").choices ) }]]>
</xp:this.getAsString>
</xp:customConverter>
</xp:this.converter>
<xp:selectItem itemLabel=""></xp:selectItem>
<xp:selectItems>
<xp:this.value>
<![CDATA[${javascript:
return FOO.UI.Utilities.getPicklist("Gender").display
}]]>
</xp:this.value>
</xp:selectItems>
</xp:comboBox>
All in all, it appears that the custom converter either is not running on the combobox value OR it is failing silently.
And shouldn’t aliases “just work”? Do we really have to do all conversion?
Thanks for any observations, insights, or plain old sympathy.