• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to populate html:select options in struts

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
That is a really big piece of pie for such a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic