I created another question hoping I could find my answer, but I went in the wrong direction. Here is that question for reference( How do I parse this into a MultiValued Map?)
I am pulling a String Array out of a property file (using Apache Configuration) and the array comes in and looks like this
name,5486984,189.658.235.215,3.158.68.15,name2,189189,189.658.218.268,3.158.68.13...
Here is part of the JSF
<f:selectItems itemValue="#{mainBean.information}" value="#mainBean.information}" />
Here is a snippet of the Java
Private String [] information;
information = config.getStringArray("information"); // This brings in this string from the property file
I’ve been referencing this http://www.horstmann.com/corejsf/refcard.html
So with what I have here, that I just posted. It will populate every element of that string array. I only want the “name” to show up and the three other values to be passed as the actual “value”.
I tried to make a Map object that is a string and a string array but JSF refuses to take it.
A
Mapshould work. You can find a concrete example in ourselectOneMenutag wiki page. The map key becomes the option label and the map value becomes the option value.You should only realize that the option value ultimately ends up in the HTML response, inside the
valueattribute of the HTML<option>element like soAs HTML is in fact plain text, you cannot represent non-standard Java objects in HTML without converting them first. A
String[]is non-standard and when you don’t explicitly specify a converter, then by default theObject#toString()result will be inlined in HTML and it would in case of aString[]look likeExactly that value is in turn thus submitted to the server side when the option is selected. However, as the value is an unintelligible sequence of characters, it isn’t possible to convert it back to the original
String[]value using Java/JSF/EL in any way.Instead of providing a converter, you can also just pass only a
List<String>containing the names around.When processing the form submit, you could just get the associated
String[]back based on the submitted name straight from the configuration file or someMapwhich is remembered as bean property.