File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes with html : options  tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "with html : options  tag" Watch "with html : options  tag" New topic

with html : options tag

san geetha
Ranch Hand

Joined: Sep 07, 2004
Posts: 44
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(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(
at org.apache.catalina.core.StandardPipeline.invoke(
at org.apache.catalina.core.ContainerBase.invoke(

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"/>

Someone kindly reply asap... cos iam totally marooned
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
<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.

Sheldon Fernandes
[ October 06, 2004: Message edited by: Sheldon Fernandes ]
Sree Jag
Ranch Hand

Joined: Oct 14, 2003
Posts: 77
hi geetha,

this is how i used html ptions:
<html:select property="mailCountryId">
<html ptions collection="countries" property="key" labelProperty="value"/>

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,

Sree Jag<br />SCJP 1.4
san geetha
Ranch Hand

Joined: Sep 07, 2004
Posts: 44
It still doesnt work!!!
Check my code below...

In the JSP:

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

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");

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
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 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");
<html:form action="" method="post">

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

if u want just try this out just directly run the page u will get the results.

so i doubt ur hapsmaps 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
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
siva kumar
Ranch Hand

Joined: Sep 03, 2004
Posts: 86
hi sangeetha

you add the values to ArrayList in Action.

and store that object in session or application.


in jsp use that like:

<html:select property="propertyname">
<html ptions collection="collection name" property="propertyname"/>

Joined: Oct 27, 2004
Posts: 3
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"/>

I too worked with same problem. Atlast I found solution. That's why I am posting this solution.
I agree. Here's the link:
subject: with html : options tag
It's not a secret anymore!