> -----Original Message----- > From: Janne Mattila [mailto:[EMAIL PROTECTED] > Sent: Thursday, August 12, 2004 1:38 AM > To: [EMAIL PROTECTED] > Subject: Accessing bean properties problem > > > 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
Why are you trying to avoid the <bean:define ? It's probably the cleanest way, other then setting a request parameter in the action that forwards to the jsp. > > (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\p > ages\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] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]