views:

134

answers:

3

Hi. 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. Many thanks.

A: 

You cant by default bean type is of type

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

or

java.lang.Object otherwise.

VinAy
A: 

Try this.

<bean:define id="index" type="java.lang.Integer" value="<%=java.lang.String.valueOf(0)%>"/>
RaviG
Your code just caused the company cat to jump out of the window!... And a java.lang.ClassCastException. It's almost the same the second example.
ian_scho
A: 

Check this

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

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

RaviG
Your example will work in many occasions such as comparing strings of numeric chars but... This is still not an java.lang.Integer bean. I wonder what will happen in the example in Chapter5 above, if someone initiated the bean with the value="07"? TY anyway.
ian_scho