This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Mar 22, 2011, 8:57 AM
7 Posts

Converter does not work with a comboBox control

  • Category: Other
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: converter
  • Replies: 2
How can I use a custom converter with a comboBox control? It does not work as expected.
 
 Here's a (simplified) example of what I try to obtain. I want to give the user a choicelist of values (for example, with the values "1","2","3","4"), and when the user selects "1", I want to store "111" in the backend document. "2" should be converted to "112", "3" to "113", ..
 
The source code looks like this: 
 

<xp:comboBox value="#{document1.nr}" id="nr1">

<xp:this.converter>

<xp:customConverter

getAsString="#{javascript:@Right(value,1)}"

getAsObject="#{javascript:'11'+value.toString(); }">

</xp:customConverter>

</xp:this.converter>

<xp:selectItem itemLabel="1" id="selectItem1"></xp:selectItem>

<xp:selectItem itemLabel="2" id="selectItem2"></xp:selectItem>

<xp:selectItem itemLabel="3" id="selectItem3"></xp:selectItem>

<xp:selectItem itemLabel="4" id="selectItem4"></xp:selectItem>

 </xp:comboBox> 
 
The above converter works perfectly with a text box control, but with a combo box, it returns an error 500 (command not handled exception).
 
After setting the "disableValidators" flag to true for the comboBox control, the conversion from the string to the data is done correctly ("2" is saved as "112"), but the reverse conversion does not work: the comboBox control in the browser does not display the corresponding value in the browser. Instead, it keeps showing the first value of the available values ("1" in the example).
 
Thanks for your thoughts on this.

 

 

Mar 22, 2011, 9:29 AM
21 Posts
Re: Converter does not work with a comboBox control
Can't you just use the itemValue parameter within the <xp:select> to set the backend value?

Mar 22, 2011, 10:37 AM
7 Posts
Re: Converter does not work with a comboBox control
 Andrew, this will work here, but not in my real-life application. In my application, I convert the selected value to a string that is calculated in a complex and performance demanding way (the code needs to iterate through views, etc....).
So, rather than perform these expensive calculations for each of the available values, I prefer to calculate only once: just for the value that was selected by the user. This works much faster (especially when the dropdown contains hundreds of values). 
 
Hence, the most straightforward approach to me is using a converter.
 
I could perform the calculations  in the "save" button of the document. But that's not an ideal solution here: I share the action buttons (save, submit, publish,...) accross many different document types, and the conversion needs to be done for only one particular type of document.

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal