Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to populate html:select options in struts

 
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.
 
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.
 
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.
 
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.
 
Ranch Hand
Posts: 1609
  • 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.
 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic