struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vince Law" <vince....@ascertane.com>
Subject RE: question regarding ActionForm
Date Mon, 03 Oct 2005 08:09:43 GMT
Niall,

I am using Struts 1.2.7.
Tomcat 5.5.9
OS - Window XP professional (with Service Pack 2)

I tried what you suggested me:
ProgramGroupForm pgForm =
(ProgramGroupForm)request.getAttribute(mapping.getAttribute());
pgForm.getType();        //same problem, returned "null"
pgForm.getDescription(); //same problem, returned "null"

If I commented out the Http client call (and hard coded the result instead),
everything worked fine again.

I switched on the "debug" mode for log4j.  The BeanUtils seemed to work
fine, it did copy the value correctly.

Is it possible that Struts get the wrong reference of the ActionForm object
and assigns it to both the Action's execute method and JSP page?  (since the
debugging info showed the correct values).

Thanks,
Vince



-----Original Message-----
From: Niall Pemberton [mailto:niall.pemberton@blueyonder.co.uk]
Sent: Sunday, October 02, 2005 5:30 PM
To: Struts Users Mailing List
Subject: Re: question regarding ActionForm


Firstly what version of Struts are you using? It probably doesn't make a
difference, but its always useful to know.

Could that call (or anything else) be affecting the attribute under which
the ActionForm is stored in the request? What happens if you retrieve the
ActionForm from the request after the service call [i.e.
request.getAttribute(mapping.getAttribute())] - is the ActionForm there and
OK?

One thing you might try is to "comment out" the call to your service in your
"SelectProgramGroupItem" action and replace it with something hard coded.
That way you can verify that it is actually the service call thats causing
the problem and not something else.

Have you checked your logs to see if anything is going wrong?

Another suggestion is to switch on logging in debug mode - the
RequestProcessor's processActionForm() method (which creates and stores the
ActionForm) logs what it does (in debug mode) - it should tell you the
scope/key that the ActionForm has been stored under. Also Commons BeanUtils
(which populates the ActionForm) logs every property that is set (in "trace"
mode) - would be useful to see if it is populating the description/type
properties OK there.

Niall

----- Original Message -----
From: "Vince Law" <vince.law@ascertane.com>
Sent: Monday, October 03, 2005 12:00 AM


> I am having a problem with ActionForm.  Please help me out, because I have
> been trying to resolve this problem for the past 4 days without getting
any
> solution for it.  Thank you so much!
>
> I defined the form in the struts-config.xml as:
>
> <form-beans>
>     <form-bean name="programGroupForm"
> type="xmps.presentation.action.form.ProgramGroupForm"/>
> </form-beans>
>
> The 3 actions that use the form-bean are:
>
> <action path="/admin/createProgramGroup"
>             type="xmps.presentation.action.EditProgramGroup"
>             name="programGroupForm"
>             scope="request"
>             validate="false">
>       <forward name="success" path="/pages/programgroup/edit.jsp"/>
>       <forward name="failure" path="/pages/programgroup/error.jsp"/>
>     </action>
>
>     <action path="/admin/saveProgramGroup"
>             type="xmps.presentation.action.SaveProgramGroup"
>             name="programGroupForm"
>             scope="request"
>             validate="false">
>       <forward name="success" path="/pages/programgroup/save.jsp"/>
>       <forward name="failure" path="/pages/programgroup/error.jsp"/>
>     </action>
>
>     <action path="/admin/selectProgramGuide"
>             type="xmps.presentation.action.SelectProgramGroupItem"
>             name="programGroupForm"
>             scope="request"
>             validate="false">
>       <forward name="success" path="/pages/programgroup/search.jsp" />
>       <forward name="failure" path="/pages/programgroup/error.jsp" />
>     </action>
>
> Everthing works perfectly fine, until a call was made to connect to
another
> webserver to retrieve some pages in one of the action's execute() method.
> For instance:
>
> in action SelectProgramGroupItem
> public ActionForward ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response)
> {
>     .....
>     ProgramGroup[] groups =
> ProgramGroupService.getService().search(searchText));  //this is a HTTP
> client call to another web-server to retrieve the program groups for a
> searchText
>     .....
> }
>
> After this point, all the returned values from calling the
ProgramGroupForm
> getter methods are "null" (regardless whatver action it was in).   It
seems
> like the way Struts handling the ActionForm got messed up. Such as:
>
> in action EditProgramGroup
> public ActionForward ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response)
> {
>     ProgramGroupForm pgForm = (ProgramGroupForm)form;
>     pgForm.getType();  //returned null
>     pgForm.getDescription(); //returned null
>
>     //however, if I tried to access the  parameter value directly, the
> values are there.
>     request.getParameter("type");  //returned correct value
>     request.getParameter("description") //returned correct value
>     .....
>
>     //I tried to work around this by setting the values in the
> ProgramGroupForm manually.
>     pgForm.setType(request.getParameter("type"));
>     pgForm.setDescription(pgForm.getDescription());
>
>     .....
>      return mapping.findForward("success");
>
> }
>
> Despite that I set the values in the setter methods manually, in the JSP
> pages that it forwarded to, when I tried to access the properties, the
> returned values are still null
>
> <html:text propperty="type" size="50" />
> <html:textarea name="programGroupForm" property="description" rows="5"
> cols="50" />
>
>
> Perhaps, I dont' know exactly how the ActionForm works in Struts.  I was
> expecting the ProgramGroupForm object in JSP is the same one that I see in
> the Action's execute.  If it is, then why I can't retrieve the property's
> value in the JSP page, after even I manually set it in the Action's
execute
> method.
>
> Regards,
> -Vince



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




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


Mime
View raw message