How to define an Integer bean in Struts 1.x

萝らか妹 提交于 2019-12-12 03:55:19

问题


How do you instantiate an Integer bean, assigning a value, in the Struts 1.x framework?

<bean:define id="index" type="java.lang.Integer" value="0"/>

or

<bean:define id="index" type="java.lang.Integer" value="${0}"/>

Results in a: java.lang.ClassCastException: java.lang.String

<bean:define id="index" type="java.lang.Integer" value="<%=0%>"/>

Results in: The method setValue(String) in the type DefineTag is not applicable for the arguments (int)

<% java.lang.Integer index = new java.lang.Integer(0); %>

Works, but makes my eyes bleed.

Note that I had to refactor iterating over a list but am now applying a filter within the iteration. This was the cleanest solution of all!

<logic:equal name="aplicacion" property="generico" value="false" indexId="index">

Maybe I need to go about this completely differently.


回答1:


You cant by default bean type is of type

java.lang.String (if you specify a value attribute)

or

java.lang.Object otherwise.




回答2:


Try this.

<bean:define id="index" type="java.lang.Integer" value="<%=java.lang.String.valueOf(0)%>"/>



回答3:


Check this

<bean:define id="index" value = "0" />

Also visit http://j2ee.masslight.com/Chapter5.html for a working example.



来源:https://stackoverflow.com/questions/2911476/how-to-define-an-integer-bean-in-struts-1-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!