• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts ArrayList Display in JSP

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
<html:option name="dateList" value="<bean:write name="element"/>"><bean:write name="element"/></html:option>
</logic:iterate>
</html:select>



hope this helps
Ramandeep S
 
Srinivas Aravala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for mistake

In JSp It would be something like this

<html:option name="dateList" value="${dateList.element}"><bean:write name="element"/></html:option>
 
Srinivas Aravala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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




 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic