wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts question 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 "Struts question" Watch "Struts question" New topic
Author

Struts question

Jay Richards
Ranch Hand

Joined: Jan 16, 2003
Posts: 58
how to i display my bean using the tags included in struts if my bean is like this:
<code>
public class person{
PersonInfoBase personinfo;
ContactInfoBase contactinfo;
....
}
public class PersonInfoBase{
getLastName();
getBirthdate();
....
}
public class ContactInfoBase{
getAddress();
getZip();
....
}
</code>
How do i display like address or lastname is i put the class person in the session.attribute:
<code>
Person person = new Person();
request.setAttribute("person",person)
</code>
Can someshow show me how wil the jsp looks like.
thanks a lot in advance.
-jay
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Moving this to the Framework forum where Struts questions go.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
<bean:write name="person" property="contactinfo.address"/>
<bean:write name="person" property="personinfo.lastName"/>
Or you could use nested tags:
<nested:root name="person">
<nested:nest property="contactinfo">
<nested:write property="address"/"
</nested:nest>
<nested:nest property="personinfo">
<nested:write property="lastName"/"
</nested:nest>
</nested:root>
If this was part of a form, you wouldn't need to use <nested:root>, since it would assume the form bean.
You'll want to be familiar with both ways of doing this as each have times when one is perferable to the other. For instance, if either one of your bean attributes was an array or collection of beans, then nested tags are usually much cleaner. But in the simple case you have here, there's no reason not to go with <bean:write>.
HTH
 
jQuery in Action, 2nd edition
 
subject: Struts question