aspose file tools*
The moose likes Struts and the fly likes How to populate html:select options in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to populate html:select options in struts" Watch "How to populate html:select options in struts" New topic
Author

How to populate html:select options in struts

Pramod Kumar
Ranch Hand

Joined: Oct 05, 2007
Posts: 40
I have a Set in session that contains values, now I need to generate those values in to a select box how can I do this.

Thanks.
ods gel
Greenhorn

Joined: Oct 09, 2007
Posts: 8
create the select as:

and in the form itself:
Pramod Kumar
Ranch Hand

Joined: Oct 05, 2007
Posts: 40
I am getting exception.


No getter method available for property name for bean under name products

<html:select property="productName">
<html ptions name="products" property="name" />
</html:select>


"products" is the Set in the session and name is the property to display in the options.
John Melton
Ranch Hand

Joined: Aug 17, 2004
Posts: 49
You'll need your code to look like this then



where myFormBean is the name of your struts form bean. Also notice the attribute collection instead of name. Give that a try


[url]www.jtmelton.com[/url]
Pramod Kumar
Ranch Hand

Joined: Oct 05, 2007
Posts: 40
Now I am having one more problem, if the Set is empty in the jsp I am getting empty select box. If the Set is empty I need to show as "No values".

How can I do this.

Thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest taking care of this in the Action class. Get the list of products from the database, check to see if the list is empty, and if so add the element "No Values" to the list prior to forwarding to the JSP.


Merrill
Consultant, Sima Solutions
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1527
I have similar troubles here... could not afford to use LabelValueBean so please spare with me.

My form-bean construct is



and action class is


i am not able to get the html:select option working,

can someone help me in filling up
? -
?? -
??? -
and ??? -

further is it possible to have a category equal to "myCategory" defaultly selected in the drop-down.


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Kishore Kumar
Ranch Hand

Joined: Oct 15, 2007
Posts: 71
public class MyForm extends ActionForm {
private String myCategory = null;
private List myCategoryList = null;
}

final List CATEGORY_LIST;
List categories = null;
categories = //populate_list_of_strings();
CATEGORY_LIST = Collections.unmodifiableList(categories);
myformobject.setMyCategoryList(CATEGORY_LIST);}

<html:select name="?" property="??">
<html ptions name="???" property="???"/> </html:select>


can someone help me in filling up
? - name of the form bean which you have mentioned in struts-config.xml file. That is: <form-bean name = "XXXXX" type = "MyForm" ></form-bean>
In t his example ? -
?? - myCategoryList
??? - XXXXX
and ??? - myCategoryList
 
jQuery in Action, 2nd edition
 
subject: How to populate html:select options in struts