• 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

Use of html:select and html:option tag

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a bean called "user" which has contains an ArrayList calles "offices" of Office objects. In the Office object there is a field called "name". The name field is accessible via getName() and setName() methods.
I want to display all these names as an HTML select tag, and I would have thought the following would work:
<html:select name="user" property="offices">
<html ptions name="user" property="offices" labelProperty="name"/>
</html:select>
But I just get the error:
No getter method available for property name for bean under name null
Any ideas?
Thanks
Tim
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But I just get the error:
No getter method available for property name for bean under name null
[/QB]<hr></blockquote>
The select tag needs to identify property where the selected office will go. The property needs to be a scalar. You could probably call this office, and add a public void setOffice( int nSelectedOffice).
You also need to set up two collections, one at getOffices(), and another at getName().
A better way to do this is

Now make the method User.getOffices return an ArrayList of Office beans, and make the Office object have a Office.getName() and Office.getOfficeId() method.
<curse>smilies</curse>
[ December 04, 2002: Message edited by: Michael Zalewski ]
 
Tim Eyre
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your help, Michael.
In my JSP I have:

I am now getting the error:
"Cannot find bean under name name" - so it is expecting the labelName attribute to be a bean
My form bean has a field "office" with the associated getOffice() and setOffice() methods.
The relevant parts of my User bean are:

And my Office bean is:

You say I need to set up two collections, one for the OfficeID (here I called it "num") and one for the name - can I not have one collection of beans, each bean having a method for num and a method for name. It seems much cleaner this way.
Should I be using the collection attribute in the option tag? Trouble is it expects a collection of beans, and all I can offer is the user bean which has a collection of office beans as an instance variable - I have tried the attribute:
collection="user.getOffices()", but to no avail.
How can I store a collection of beans as a bean? - surely I can only store a collection of beans as an ArrayList (or some other Java collection)?
Thanks
Tim
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic