Yes you do, the form is passed in as one of the parameters to execute().
The typical pattern is for the action to be invoked via an action
mapping, populate the form bean and forward to the JSP. It's during this
action processing that you copy your business data into the form bean,
thus initializing it.
The form in the JSP is then bound to the form bean, both reading from
and writing to the same place. When the form is submitted, another
action is invoked and in that action you copy the appropriate data from
the form to wherever you need it to complete the operation.
To answer your earlier question, you *can* have a form which takes its
values from a bean other than the form bean -- I think you've already
had that working for some input types. However, in the case of
checkboxes, that's going to be problematic, since the input's value is
doing double duty -- it's specifying the value that should be submitted
*if* the checkbox is selected, and also specifying the value that the
checkbox property must have for it to be considered selected already.
If you don't want to copy the permission data from your model into the
form bean before rendering the form, you can do as previously suggested
and put the entire business object into the form bean; that solution
actually doesn't prevent the properties being written/updated. There are
problems with this approach for certain types of inputs, but for boolean
values rendered as checkboxes it should work fine.
L.
Anthony N. Frasso wrote:
I guess I don't follow....
How do I prepopulate the form bean? I have a list
page which lists all of the roles in the system. When
the form on the list page is submitted, I can retrieve
the ID of the role that the user wants to edit. In
the action class I then retrieve that role, and put it
into the request scope.
The question is... how do I pre-populate the form bean
with that role? I don't have access to the form bean
yet from the action class.
Regards,
Anthony Frasso
--- Puneet Lakhina <[EMAIL PROTECTED]> wrote:
On 8/30/06, Anthony N. Frasso <[EMAIL PROTECTED]>
wrote:
Actually, that's incorrect. I want to *read* from
the
Role bean. I want to *write* to the form bean. I
just don't know how to go about it yet. :) It
seems
like I have to read/write to the same form bean,
which
doesn't make sense, because I don't have the form
bean
until I get to the JSP page, so there's no way to
initialize it.
Actually you have probably missed the total concept
of prepopulating. You
put initial values in you form beans, when your JSP
page loads your struts
tags call the getter methods of the relevant to put
initial values in your
fields. And then when the form is submitted setter
methods are called
followed by validate(if present and the action has
set validate="true"), and
in case of no errors in validate the action methods
execute is called which
in turn returns a forward to a page.
so your cycle for a normal form submit is like this.
request for jsp->prepoulate using getter->jsp
rendered->submit->call
setters->validate->if no errors ->execute of
Action->forward
--
Puneet
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]