tags:

views:

26

answers:

1

I am having a simple string array in my bean as

public String[] colors = new String[]{"red", "blue", "green"};

and trying to display these colors from my xhtml as

<h:outputText value="#{myBean.colors[0]}"/>

but I am getting a java.lang.NumberFormatException: For input string: "colors"

java.lang.NumberFormatException: For input string: "colors"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.
java:48)
        at java.lang.Integer.parseInt(Integer.java:447)
        at java.lang.Integer.parseInt(Integer.java:497)
        at javax.el.ListELResolver.coerce(ListELResolver.java:166)
        at javax.el.ListELResolver.getValue(ListELResolver.java:51)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
+1  A: 

This should work just fine. Your problem lies somewhere else. The stacktrace at least indicates that you're trying to do something like #{myBean.colors['colors']}. This obviously won't work.

Either you aren't running the code you think you're running, or the actual problem is bigger and you eliminated too much so that it by coincidence ends up with a workable snippet in the question here.

BalusC