• 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

with html : options tag

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the previous responses

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)


The jsp code is sthg like this:


<html:select property="strName" size="1">
<logic:iterate id="sample" name="SampleFormBean">
<html ptions labelProperty="arlName" name="SampleFormBean"/>
</logic:iterate>
</html:select>



Someone kindly reply asap... cos iam totally marooned
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html:options> renders a Collection of Select Options. You do not need to use the surrounding <logic:iterate> tag.
See the documentation for <html:options> 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.

Sheldon Fernandes
[ October 06, 2004: Message edited by: Sheldon Fernandes ]
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi geetha,

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.

hope this helps,
Seshu
 
san geetha
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It still doesnt work!!!
Check my code below...

In the JSP:


<html:select property="selectCriteria">
<html ptions collection="criteria" property="key" labelProperty="value"/>
</html:select>



In the FormBean:


private HashMap criteria;
private String selectCriteria;
public HashMap getcriteria()
{
return criteria;
}

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!!!
 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>



<%

java.util.HashMap criteria = new java.util.HashMap();
criteria.put(new Integer(1),"Sangeetha");
criteria.put(new Integer(2),"Madhavan");
request.setAttribute("criteria",criteria);
%>
<html:form action="login.do" method="post">

<html:select property="userName">
<html ptions collection="criteria" property="key" labelProperty="value"/>
</html:select>
</html:form>

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
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The naming convention of your accessor and mutator methods for property criteria is incorrect (unless you have typed it incorrectly in the post).

property: criteria
accessor: getCriteria() (Capital 'C')
mutator : setCriteria() (Capital 'C')

Sheldon Fernandes
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sangeetha

you add the values to ArrayList in Action.

and store that object in session or application.

and

in jsp use that like:



<html:select property="propertyname">
<html ptions collection="collection name" property="propertyname"/>
</html:select>
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this code:

In the placeof beanName(as given in your struts-config.xml) write the name of your bean

<html:select property="criteria" name="beanName">
<html ptionsCollection name="beanName" property="criteria" label="key" value="value"/>
</html:select>

I too worked with same problem. Atlast I found solution. That's why I am posting this solution.
 
reply
    Bookmark Topic Watch Topic
  • New Topic