• Post Reply Bookmark Topic Watch Topic
  • New Topic

is it possible to concatenate string in a selectonechoice component?

 
Winston Liek
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<tr:selectOneChoice value="#{bean.aValue}" required="true">
<f:selectItem itemLabel="Option1" itemValue="1"/>
<f:selectItem itemLabel="Option1" itemValue="2"/>
<f:selectItem itemLabel="Option1" itemValue="3"/>
</tr:selectOneChoice>

Supposed that selectItem loads a list from the database.

But I want to display "Option1 - testing" without modifying database value.

testing is a string datatype in the backing bean
 
Jarrod Rackley
Ranch Hand
Posts: 30
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using a LinkedHashMap and set the key as the contacted string and the value as... value.



Then call it like:




Keep seeing something I typed wrong.
 
Tim Holloway
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a number of things wrong with the preceeding example, starting with the fact that it has the selectItem and selectitems tags confused.

I'm not sure, but this sounds like a common situation that I deal with:



The "choices" property is a List or array of SelectItem objects constructed from a database fetch (or whatever). By prepending the list with a manually-supplied empty value, I can avoid accidentally defaulting to a data value when I don't want to and I can use the "required" attribute on the control to enforce that the user must select a valid value. And this way I don't have to pollute the backing bean's selection list model with a null entry that external to what it pulled from the database.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!