• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to populate html:select options in struts

 
Pramod Kumar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create the select as:

and in the form itself:
 
Pramod Kumar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pramod Kumar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kishore Kumar
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic