wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts ArrayList Display in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts ArrayList Display in JSP" Watch "Struts ArrayList Display in JSP" New topic
Author

Struts ArrayList Display in JSP

Srinivas Aravala
Greenhorn

Joined: Aug 20, 2005
Posts: 6
hi ,

I am new to struts i am stuck on an issue in the code of my project as part of that
i need to populate an Arraylist elements into an html option in the JSP i mean a drop down
with value and label being the same as option value.

My ActionClass Contains

i am assigining in the following way in to my bean in one of my previous action class


ArrayList alist = new ArrayList();
for (int i=1;i<=30;i++)
{
alist.add(i);
}
atdForm.setAtDate(alist);




my ActionForm contains the below contents

ArrayList atDate = new ArrayList();

public ArrayList getAtDate()
{
return atDate;
}

public void setAtDate(ArrayList altDate)
{
this.atdate = altDate;

}







So now i am trying to generate a DropDown in my jsp




<logic:iterate id="element" name="AtdAForm" property="atdate">
<html:select property="selList">
<html:option name="dateList" value="<bean:write name="element"/>"><bean:write name="element"/></html:option>
</logic:iterate>


But i am unable to generate the desired result , i am not sure i am coding in the correct way , or can suggest the best way .Appreciate your help. Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
you can do something like this

ArrayList alist = new ArrayList();
for (int i=1;i<=30;i++)
{
alist.add(i);
}
request.setAttribute("alist",alist);

then in jsp you can retreive this as given below
<html:select property="selList">
<logic:iterate name="alist" id="element"> // as name is name of attribute in some scope
<htmlption name="dateList" value="<bean:write name="element"/>"><bean:write name="element"/></htmlption>
</logic:iterate>
</html:select>



hope this helps
Ramandeep S
Srinivas Aravala
Greenhorn

Joined: Aug 20, 2005
Posts: 6
Hi Ramandeep,

Thanks for your reply , i have tried in the way you suggested but still i am having the below problem

javax.servlet.ServletException: org.apache.jasper.JasperException: /GetAttDetails.jsp(111,61) equal symbol expected
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

seems


RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Sorry for mistake

In JSp It would be something like this

<htmlption name="dateList" value="${dateList.element}"><bean:write name="element"/></htmlption>
Srinivas Aravala
Greenhorn

Joined: Aug 20, 2005
Posts: 6
Hi Ramandeep,

Thanks for your revert, seems doesnt have attribute name

javax.servlet.ServletException: org.apache.jasper.JasperException: /GetAttDetails.jsp(115,0) Attribute name invalid for tag option according to TLD
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

but i was able to solve the issue in the following way




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts ArrayList Display in JSP