This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes dynamically create fields based on bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "dynamically create fields based on bean" Watch "dynamically create fields based on bean" New topic
Author

dynamically create fields based on bean

shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
I have a Address bean and I want to create the fields based on this
Address getters/setters for below fields

street
city
state
zip
country

here is my form declaration.

<form-property name="address" type="com.mycompany.Address"/>

How to use this info to create my fields in my jsp page dynamically?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you just want to display the fields, use the "dot" notation to do so. Example:

If you're looking for a way to automatically figure out what properties the bean has and display them all, there's no facility in Struts to do that. It could be done, but you'd have to do most of the coding yourself. You may want to check out what utilities are available in the Apache Commons BeanUtils project.
[ March 22, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: dynamically create fields based on bean