> Would somebody please tell me the proper way to set a form property from a
> request parameter?

The short answer to this is that you don't - Struts does all the work for
you.

If the submitted query string contains 'mode=foo', then Struts will call
setMode("foo") on your form bean before your Action's perform() method is
called. You can access the value using your form bean's getMode() method.

If you need to set up 'mode' as a hidden field so that 'mode=foo' is always
submitted, then you only need:

<html:hidden property="mode"/>

When the JSP is processed, Struts will call your form bean's getMode()
method and use the result to generate the 'value' attribute of the <input>
tag.

Hope this helps.

--
Martin Cooper

----- Original Message -----
From: "Fickes, Vic" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 06, 2001 11:24 AM
Subject: setting a property from a parameter


> Would somebody please tell me the proper way to set a form property from a
> request parameter?
>
> After reading the docs on the html:hidden tag I thought I could do it
using
> the value attribute:
>
>   <html:hidden property="mode" value="<%= request.getParameter('mode')
%>"/>
>
> But this doesn't appear to call the setMode() method of the Form.
>
> Then I tried using the bean:define tag, again using the value attribute:
>
>   <bean:define id="mode" property="mode" name="testForm"
>                value="<%= request.getParameter('mode') %>"/>
>
> But this doesn't work either.
>
> Currently, this is the only way I found to do it, but it seems kind of
> klunky.
>
>   <bean:define id="testForm" name="testForm"/>
>   <%
>
((web.app.test.TestForm)testForm).setMode(request.getParameter("mode"));
>   %>
>
> Thanks in advance,
> Vic


Reply via email to