Welcome to the IBM Collaboration Solutions Community IQJam.
UsernamePassword
Reset Password | Register
   
Home | Leader Board | Tags | Help
Problem getting correct submitted value using aliased keyword list in an ComboBox 
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.

Domino Development / XPages
David Hocking - about 1 year ago |  |  | Viewed 328 times

There are 3 answers

1votes
Hi David,
 
You're right, what HTML are you seeing being generated by the XPage for the combo box? You should see something like: 
 
<select id="view:_id1:comboBox1" name="view:_id1:comboBox1" class="xspComboBox" size="1">
    <option value="M">Male</option>
    <option value="F">Female</option>
</select>
 
If not then that will be the root of the problem. 
 
Matt 


Matt White - about 1 year ago | 
Voting
Vote on the answer to show whether you think the answer is correct or useful to the rest of the community.

Answers with more votes are more visible to the rest of the community


0votes
Hi Matt,
Thanks for the reply. That is what I'm seeing in Firebug, but what it is saving is "Female", not "F".

Here's what I pulled out of Firebug -
<select id="view:_id1:comboBox1" name="view:_id1:comboBox1" class="xspComboBox" size="1">
<option value=""></option>


David Hocking - about 1 year ago | 
Voting
Vote on the answer to show whether you think the answer is correct or useful to the rest of the community.

Answers with more votes are more visible to the rest of the community


1votes
Hi David, looks like my reply went the way of the dodo, so I'll re-post.  I tried a combobox with aliases on 8.5.2 just now & it did save the alias value to the document.  On the combobox Values tab, I calculated the values as follows:
 
list = @DbLookup( @DbName(),"LU_Keyword", "Colour", 2 );
var newList = new Array();
for (i=0;i<list.length;i++){
    newList.push(list[i] + "|" + i)
};
newList;
 
The generated source looks very similar to yours:
<select id="view:_id1:comboBox2" name="view:_id1:comboBox2" class="xspComboBox" size="1">   
    <option value="0">Black</option>
    <option value="1">Blue</option>
    <option value="2">Chartreuse</option>
    <option value="3">Green</option>
    <option value="4">Red</option>
    <option value="5">White</option>
    <option value="6">Yellow</option>
</select>

If I pick "Red", "4" gets saved to the document field.  In Read mode, the XPage combobox displays "4", and if I switch to Edit mode, "Red" is pre-selected in the combobox.  You could try using a similar formula to populate the picklist & see if that makes a difference.  Also, on the "All Properties" tab for the combobox, the "value" parameter is what's bound to the datasource receiving field, and there's no "defaultValue" defined.  Sometimes those things can throw a wrench into things.
 
Hope some of this helps.


Judy Kilpinen - about 1 year ago | 
Voting
Vote on the answer to show whether you think the answer is correct or useful to the rest of the community.

Answers with more votes are more visible to the rest of the community