Let's say I have a collection of Choice objects, each having attributes key and name. I want to iterate the collection on JSP, display it's contents and add a delete button for each choice. Delete button value should contain "delete_" appended with each choice's key. Following works:

(1)

<logic:iterate id="choice" name="choicesForm" property="choices">
<tr>
<td><bean:write name="choice" property="key"/></td>
<td><bean:write name="choice" property="name"/></td>
<bean:define id="choiceKey" name="choice" property="key" />
<td><html:image src="delete.gif" value="<%= "delete_" + choiceKey %>" /></td>
</tr>
</logic:iterate>


the problem is the required additional <bean:define> that I would like to avoid. Trying

(2)

<logic:iterate id="choice" name="choicesForm" property="choices">
<tr>
<td><bean:write name="choice" property="key"/></td>
<td><bean:write name="choice" property="name"/></td>
<td><html:image src="delete.gif" value="<%= "delete_" + choice.getKey() %>" /></td>
</tr>
</logic:iterate>


just results in

org.apache.jasper.JasperException: Unable to compile class for JSP

3\server\default\work\MainEngine\localhost\struts-helloworld\pages\jannen\listChoices_jsp.java:200: cannot resolve symbol
[javac] symbol : method getKey ()
[javac] location: class java.lang.Object
[javac] _jspx_th_html_image_2.setValue( "delete_" + choice.getKey() );


since choice is Object... Adding the correct cast results in horrible

<td><html:image src="delete.gif" value="<%= "delete_" + ((com.someCompany.someProject.somePackage.Choice)choice).getKey() %>" /></td>

I guess I could improve on that by adding some imports to have this

<td><html:image src="delete.gif" value="<%= "delete_" + ((Choice)choice).getKey() %>" /></td>

but then I am left with the task of updating the imports on JSP pages and I feel that there could/should be a simpler way. Any ideas? Unfortunately JSP 2.0 is not an option for me at the moment.

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to