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

How to use html:options

Prakash Dwivedi
Ranch Hand

Joined: Sep 28, 2002
Posts: 452
Hello friends,
I am trying to use html:select tag with html ptions but unable to use it.
i have one jsp page, one form class, in my form class i have following method
public Iterator getCountryList()
{
System.out.println("i am in getCountryList");
ArrayList country = new ArrayList();
country.add("India");
country.add("USA");
country.add("UK");
country.add("Gremany");
country.add("France");
countryList = country.iterator();
return countryList;
}
following is the code i used in my jsp page
<html:select property="countryList">
<html ptions collection="user"/>
</html:select>
Here user is a bean which is bound in session and contains countryList as a variable(apart from form class)
actually i am very much confused about these attributes, and not able to use them ptoperly
I am getting following error
javax.servlet.jsp.JspException: Cannot create iterator for app.LogonForm@14dc

thanx


Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
Lalitha Chandran
Ranch Hand

Joined: Jul 03, 2003
Posts: 92
Hi
Here is how I use the html select options tag. I am using the LabelValueBean Class which comes along with struts. org.apache.struts.util.LabelValueBean)
JSP File:

Action File:

Action Form file

Hope this helps.
Lalitha
Prakash Dwivedi
Ranch Hand

Joined: Sep 28, 2002
Posts: 452
thanks Lalitha
xinglee vn
Greenhorn

Joined: Jul 09, 2003
Posts: 9
Hi !
can you show me how to set value for <html ption> using bean ? (I am beginner in Struts)
i have :
<logic:iterate id="exp" name="beanname">
<html:select property="Dept">
<html ption name="exp" value="<bean:write name="exp" property="id">"/>
</html:select>
</logic:iterate>
but it doesn't work ! pls help me as soon as posible . it's very Urgen . Thanks a lot
Ron Yoshimochi
Greenhorn

Joined: Oct 06, 2003
Posts: 3
I am new to struts and I tried the sample below. Could you post the struts-config.xml
Thanks
Ron
Originally posted by Lalitha Chandran:
Hi
Here is how I use the html select options tag. I am using the LabelValueBean Class which comes along with struts. org.apache.struts.util.LabelValueBean)
JSP File:

Action File:

Action Form file

Hope this helps.
Lalitha
Kavita Ghia
Ranch Hand

Joined: Oct 10, 2000
Posts: 91
Thanx Lalitha, your code really helped !!!
A Patel
Greenhorn

Joined: Aug 19, 2005
Posts: 14
Thanks Lalitha - I was trying to populate a dates drop down for the past two weeks and your code (using LabelValueBean) solved my problem in a matter on minutes.

Thanks a ton!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to use html:options