Just to further Dave is saying. If the class is a proper JavaBean with a zero-argument constructor, if it is null during autopopulation, then the framework will automatically instantiate it.
For fancier implementations, we can even provide a custom type converter for a class, that could do something like lookup a complete City record from a database based on the ID. * http://struts.apache.org/2.x/docs/type-conversion.html HTH, Ted. On Nov 15, 2007 5:15 PM, Dave Newton <[EMAIL PROTECTED]> wrote: > Or you can put the city.id in the form as a hidden > field. > > d. > > --- "Hernandez, David" <[EMAIL PROTECTED]> > wrote: > > > > > > Sorry, The problem was that building has a member > > variable that is a > > class (City) which is going out of scope. > > Building.toString() calls > > city.getId() throwing the exception and returning > > null . . . > > Now, to keep that in scope somehow . . . > > > > -----Original Message----- > > From: Hernandez, David > > Sent: Thursday, November 15, 2007 3:12 PM > > To: 'Struts Users Mailing List' > > Subject: RE: Form Submission Question > > > > I'm having a problem with my bean going out of > > scope. The form is > > populated with the bean information fine, but when I > > submit building is > > null? How do I keep it in scope? Do I have to pull > > it back out of the > > ActionContext? > > > > public class BuildingFormTestAction extends > > ActionSupport { > > private static final long serialVersionUID = > > 6692492667406189130L; > > private Building building; > > public String init() throws Exception > > { > > //Fetch Building from db . . . > > return ActionSupport.SUCCESS; > > } > > public String execute() throws Exception > > { > > System.out.println("Submitting: "); > > System.out.println(building);//PRINTS NULL! > > return ActionSupport.SUCCESS; > > } > > public void setBuilding(Building b) > > { > > building = b; > > } > > public Building getBuilding() > > { > > return building; > > } > > } > > > > Here's the JSP Form: > > <s:form action="setBuilding" method="POST"> > > <s:push value="building"> > > <s:textfield label="Name" name="name" /> > > <s:textfield label="Address" name="streetAddress" > > /> > > <s:textfield label="Lat" name="latitude" /> > > <s:textfield label="Long" name="longitude" /> > > <s:checkbox label="Active" name="active" /> > > <s:textfield label="Zip" name="zip" /> > > <s:submit /> > > </s:push> > > </s:form> > > > > And Struts.xml exerpt: > > <action name="form" class="BuildingFormTestAction" > > method="init"> > > <result>/buildingFormTest.jsp</result> > > <result name="input">/error.jsp</result> > > </action> <action > > name="setBuilding" class="BuildingFormTestAction" > > method="execute"> > > <result>/buildingFormTest.jsp</result> > > <result name="error">/error.jsp</result> </action> > > > > -----Original Message----- > > From: Dave Newton [mailto:[EMAIL PROTECTED] > > Sent: Thursday, November 15, 2007 2:20 PM > > To: Struts Users Mailing List > > Subject: Re: Form Submission Question > > > > --- Gary Affonso <[EMAIL PROTECTED]> wrote: > > > Dave Newton wrote: > > >> The action that *processes* the form submission > > may extend > > >> ActionSupport. > > > > > > Dave knows that, of course, but I didn't want the > > emphasis on > > > "*processes*" above to make you think > > ActionSupport was only > > > appropriate for form processing actions. > > > > Yep, that was a good clarificaton to make :) > > > > d. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]