开发者

netbeans 7.0 shows error in Struts2 select tag .. netbeans version 6.9 does not show this error [duplicate]

This question already has an answer here: Struts 2 #{} giving compilation error in Netbeans 7.3 (1 answer) Closed 5 years ago.
<s:select
  name="PenaltyPercentage"
  id="PenaltyPercentageId"
  list="#{'7.5%':'7.5%', '15.0%':'15.0%'}" <!-- shows error in this line -->
  headerKey=""
  headerValue="Please Select"
  emptyOption="false">
</s:select>

the error messages reads 开发者_Python百科as below

Encountered ":" at line 1, column 9.
Was expecting one of:
"}" ...
"." ...
"]" ...
">" ...
"<" ...


Netbeans 7 uses JSP EL 2.1 which uses the # character now.

For me (Netbeans IDE 7.0 RC1) it compiles fine and works although the line is flagged with an error. If glassfish will not execute the jsp then the following link shows how to disable JSP EL in a JSP 2.1 container (bottom of the following link).

http://struts.apache.org/2.0.14/docs/ognl.html

Probably the easiest solution at this time is to add the class of the map:

#@java.util.LinkedHashMap@{ "foo" : "foo value", "bar" : "bar value" } 

Found in this thread: http://struts.1045723.n5.nabble.com/s2-JSF-JSP-EL-vs-OGNL-EL-td3528303.html

For information on the JSP EL 2.1 See: http://jcp.org/aboutJava/communityprocess/final/jsr245/index.html


You are probably just showcasing the issue but just to be sure, if you supply a list rather than a map then the value returned to the server will be the same as the displayed value. So the following produces the same select box and does not produce an error:

<s:select
  list="{'7.5%','15.0%'}" <!-- does not show error -->
  headerValue="Please Select"
  emptyOption="false">
</s:select>

I spent a little time seeing if I could change the JSP EL version in Netbeans 7 without success, also tried to find a way to disable JSP EL error checking without success. So if you must use OGNL maps in your JSP either disable JSP EL (which isn't an attractive option for some) or explicitly declare the map as shown.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜