struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davide Bruzzone <Davide.Bruzz...@ngt.com>
Subject Struts - Passing a form object "through" an action
Date Fri, 13 Sep 2002 20:33:04 GMT
Greetings all...

I'm including a message that I posted on USENET a couple of days ago
below... Any help/insight/someone pointing out what a silly mistake I'm
making would be greatly appreciated:

Wayne wrote:

By default, a FormBean is session-scoped.  That means it will be in the 
session context under its form name.  Just go look at it and get the 
stuff you want.

Wayne

<interjection>
Yes, I can see the form bean in the session in my debugger... The values are
correct (i.e. They are the values from the previous page). They just never
make it back out to the page that's sent to the browser.
</interjection>

I wrote:

>Greetings all...
>
>Here's what we're trying to do: When an HTML form is posted to a
>Struts action, we'd like to take the form object that's passed as a
>parameter into the action method and somehow pass it back out to the
>view (in our case a JSP) that the action forwards the request to (So
>that the resulting view's values can be based on this form object's
>attributes).
>
>i.e...
>1) Form 1 has a field that contains the value "Foo"
>2) The form is submitted to an action that forwards the request to
>Form 2 (or back to Form 1). This second form also has a text field,
>and it should contain the value "Foo" when it (be it Form 2 or Form 1)
>is rendered.
>
>Here are some code snippets...
>
>- The JSP page:
>
><html:form action="/Test.do?action=view">
>	<html:select property="sel">
>		<%-- TestVector is the name of a Vector object in the
session --%>
>		<html:options name="TestVector"/>
>	</html:select>
>	
>	<input type="submit" value="Submit"/>
></html:form>
>
>- struts-config.xml:
>
><form-beans type="org.apache.struts.action.ActionFormBean">
>        <form-bean name="TestForm" type="com.company.TestForm" />
></form-beans>
>
>...
>
><action name="TestForm" path="/Test" 
>    type="com.company.TestAction" 
>    scope="request" 
>    input="/test.jsp" 
>    parameter="action">
>    <forward name="success" redirect="true" path="/test.jsp" />
></action>
>
>- The appropriate action class code:
>
>...
>
>if (form == null) {
>  form = new TestForm();
>            
>  if ("request".equals(mapping.getScope()))
>    request.setAttribute(mapping.getAttribute(), form);
>  else
>    session.setAttribute(mapping.getAttribute(), form);
>}
>          
>TestForm testForm = (TestForm)form;
>            
>testForm.setSomething("Two");
>        
>- The appropriate form class code:
>
>private String something = null;
>
>public void setSomething(String newSomething) {
>    something = newSomething;
>}
>
>public String getSomething() {
>    return something;
>}
>
>Since Struts is able to reload a form if there are errors on it, this
>should be a simple matter. However, the code above just isn't working.
>It looks like even though we put an updated form object into the
>request or session, a new form object is being created when the
>request is forwarded.
>
>Any help, pointers to information, etc. would be greatly appreciated.
>
>Thank you.
>
>Dave Bruzzone

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message