I want to load values into the select html tag using <html : options> tag. But the values for the same has to be fetched from the database.
My question is where do i fill the arraylist for this "options" tag... in formBean or the Action Class... I tried adding the code into the constructor of the action class, a static block and finally in the perform method also...but nothing seems to work.
I get the following error
org.apache.jasper.JasperException: Cannot create iterator for this collection at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
Someone kindly reply asap... cos iam totally marooned
Sheldon Fernandes
Ranch Hand
Joined: Aug 18, 2004
Posts: 157
posted
0
<htmlptions> renders a Collection of Select Options. You do not need to use the surrounding <logic:iterate> tag. See the documentation for <htmlptions> for correct usage.
As for populating the collection, I find the action a good place for setting the form bean elements to values required to be displayed in the view. You could use the constructor to show default values in the view.
this is how i used html ptions: <html:select property="mailCountryId"> <html ptions collection="countries" property="key" labelProperty="value"/> </html:select>
In my ActionForm i have the countries attribute as a HashMap. that worked for me.
And regarding where to put the logic for retrieving the collection values, i think it's better to put in actionform because when the validation for a jsp fails, the collection values will not be repopulated if the logic is not in the actionform.
public void setcriteria(HashMap value) { criteria = value; }
public String getSelectCriteria() { return selectCriteria; }
public void setSelectCriteria(String value) { selectCriteria = value; }
In the Action class:
HashMap criteria = new HashMap(); criteria.put(new Integer(1),"Sangeetha"); criteria.put(new Integer(2),"Madhavan"); objFormBean.setCriteria(criteria);
Please help me... i know iam making a mistake somewhere... but iam unaware of where the error is!!!
sreenath reddy
Ranch Hand
Joined: Sep 21, 2003
Posts: 415
posted
0
Hi sangeeta
Check out properly whether that hashmap is getting persisted properly or not ....mean i doubt the way in which u r coming to that jsp.............as by that time the scope of ur form bean is lost
because i tested the same using the folloing code with out any action class but i have a formbean
if u want just try this out just directly run the page u will get the results.
so i doubt ur hapsmaps persisatnce....so bettet to debug before this <html:cptions jsut try to print the hashmap in ur formbean i am sure that will be null
Sheldon Fernandes
Ranch Hand
Joined: Aug 18, 2004
Posts: 157
posted
0
The naming convention of your accessor and mutator methods for property criteria is incorrect (unless you have typed it incorrectly in the post).