Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts ArrayList Display in JSP

 
Srinivas Aravala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic