I used example from book Struts in Action page 296 (one collection stored as separate bean) according to which collection has been put directly in the request, session or application scope under the name ss:
<html:select property="ss">
<html:options collection="ss"/>
</html:select>
The problem is in JSP I get error:
java.lang.IllegalArgumentException: No name specified!?
refering to line <html:options collection="ss"/>
Anybody?
I also tried this:
<bean:define id="ss" name="tt"
property="ss" type="java.util.Collection"/>
<html:options collection="ss" property="value"
labelProperty="label"/>
the form tt is DynaValidatorForm
but get error:
javax.servlet.jsp.JspException: No getter method for property ss of bean tt
In my action I do:
ArrayListal = new ArrayList();
al.add( new String("str1" ));
...
request.setAttribute( "ss", al );
Consider an arraylist called joel which i return to a jsp page from my action class
request.setAttribute("goan", joel);
return (mapping.findForward("success"));
Here's how i display the contents of the ArrayList in my jsp page
<logic:present name="goan" scope="request">
<html:select size="1" property="goan" style="color: #000000; font-family: Garamond; font-size: 12pt">
<logic:iterate name="goan" id="obj" type="java.lang.String">
<html:option value="<%=obj%>"><bean:write name="obj"/> </html:option>
</logic:iterate>
</html:select>
Hope this helps
It should work like this
<html:select property="your property name">
<html:options collection="arrayList name" value="gettermethod name of your bean" labelProperty="getter method name of your bean containing description" />
</html:select>
let me know if it still doesnot work. I will give the code
This is not the best way of doing this as scripting in jsp is not a good idea and I haven't tried this for html:option, nonetheless, here's one way to do it:
Try setting the value in var first
<!--Looping logic using c:forEach-->
<c:forEach var="variable1" item="some_object">
<c:set var="var1" value="${variable1}" scope="page'/>
<!--html:select blah blah-->
<html:options value="><%=pageContext.requestAttribute('var1').toString()%>">
<!--blah blah-->