开发者

How to access string[] in xhtml page

开发者 https://www.devze.com 2023-01-01 19:34 出处:网络
I am having a simple string array in my bean as public String[] colors = new String[]{\"red\", \"blue\", \"green\"};

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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消