struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Kehoe" <ke...@fortuity.com>
Subject DynaActionForm values disappear
Date Thu, 11 Jul 2002 01:37:37 GMT
I'm using a DynaActionForm and instantiating it and populating it 
with initial values in a servlet 2.3 Listener sessionCreated() event.

When I use the DynaActionForm in a form on a JSP page, the populated 
values have disappeared. I've searched the archives and various FAQs 
and combed through the source (Struts 1.1b1) and I can't see why it 
goes wrong. What am I missing?

Here's the Listener bit:
    public void sessionCreated(HttpSessionEvent hse) {
        HttpSession session = hse.getSession();
		... code for a (DynaActionForm) dynaClass.newInstance() ...
		instance.set("foo","Foo");
		session.setAttribute("my_form", instance);
    }
I can snoop and see "foo" is in "my_form" and it's in the session.

Then I request a page "entrypage" that uses the DynaActionForm in a
form, 
like this:
	<html:form styleId="form" name="my_form" 
		scope="session" 
		type="org.apache.struts.action.DynaActionForm" 
		action="/myapp" 
		onsubmit="JavaScript:document.forms.form.action=
		\'myapp.do?action=test\'" >

This bit comes up empty the first time, when it should have the 
intial value of "Foo":
<html:text name="my_form" property="foo"/>

It looks like the RequestProcessor processActionForm() call to the
RequestUtils.createActionForm() method is not finding "my_form" in
the session and instead is instantiating a new "my_form" without any
values.

As you can see, I'm using a DispatchAction object. 
Here's the method that gets triggered:
	public ActionForward test(ActionMapping mapping,
		ActionForm inForm,
		HttpServletRequest request,
		HttpServletResponse response)
		throws ServletException {
		DynaActionForm form = (DynaActionForm) inForm; // just a cast!
		if(form.get("foo") != null) { 
			log.debug("form.get('foo') is \"" 
		        + form.get("foo") + "\"");
		} else log.severe("no form parameter named foo!"); 
		return mapping.findForward("entrypage");
	}

When I go back to the "entrypage", "foo" has been properly populated 
with the value from the request parameter and
<html:text name="my_form" property="foo"/> 
shows whatever I submitted in the form.

Here's the struts-config.xml bits:

<form-bean  name="my_form"
	dynamic="true"
        type="org.apache.struts.action.DynaActionForm">
	<form-property name="foo" type="java.lang.String"/>
</form-bean>

    <action    path="/myapp"
               type="myapp.struts.action.MyAction"
               parameter="action"
               scope="session"
               name="my_form"
               input="/somebogus.jsp"
               validate="false">
    </action>

So what could be wrong?
-- 
  Daniel
  kehoe@fortuity.com

--
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