aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "with html : options  tag" Watch "with html : options  tag" New topic
Author

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


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

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.

and

in jsp use that like:



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

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"/>
</html:select>

I too worked with same problem. Atlast I found solution. That's why I am posting this solution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: with html : options tag
 
Similar Threads
My html:select is not working
conditionally generated optionsCollection?
Using logic:iterate in select box
Exception thrown by getter...... urgent!
Error while Populating html:options with validations!!