I'm going to have a good lesson that will show exactly what you want, but
until then, if you want a quick preview of the Action class, put it here:

http://www.reumann.net/misc/EmployeeAction.txt

You are following an example where I showed using a separate Action for each
behaviour whereas the link above shows a DispatchAction. It's just a short
cut for putting related tasks in one action versus using separate actions.
Regardless, though, let's assume your separate Action approach which is just
fine.

I typically would make a SetUpAction that you would call "before" you
forwarded to the JSP page where you would be editing the form. So let's
assume you went to edit the Employee from a link you clicked on, the process
would be...

1) Click on link, passing something like an employeeID
2) link submits to your SetUpAction
3) In SetUpAction it checks the Request to see if an "employeeID" was passed
to it. If ti was, you go database get your Employee object (EmployeeDTO
following your old example) and then you can use BeanUtils like you did
before...
BeanUtils.copyProperties(yourForm, employeeDTO ); Foward success brings you
to the "employeForm.jsp" page.
4) employeeForm is now all set up with the employee information and clicking
'submit' would bring you to an UpdateEmployeeAction to do the actual update
(just like you did for the InsertEmployeeAction).

You can easily reuse the form for doing both "inserts" and "updates."
Typically you'll have to do a little bti of logic for some of the verbage to
decide what to display (ie is header "Insert Employee" or "Update
Employee"). You can base your logic to decide what to display on various
things (in this case it could be as simple as looking for an "employeeID" ..
if you have one then you know you are doing an update... if you don't than
you are doing an insert, but of course there are plenty of other ways to do
it as well.

On 12/25/05, Vikrama Sanjeeva <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
>     Here is the sequence:
>
> 1: User fill up's "employeeForm.jsp" which have multiple text fields,
> radio
> buttons, text area's and dropdowns.
> 2: On pressing "Submit" button in "employeeForm.jsp",
> "InsertEmployeeAction"
> is called which  do the following:
>
> 2.1) BeanUtils.copyProperties( employeeDTO, employeeForm)
> 2.2) DataBaseService.insertEmployee (employeeDTO)
> 2.3) return mapping.findForward("success");
>
> Now, I want to call same "employeeForm.jsp" in "editable" mode, such that
> all the fields (text fields, radio buttons, text area's and dropdowns) are
> "pre-populated". What approaches are there to achieve this? I'm looking
> for
> a way which uses same  BeanUtils.copyProperties() and copy the employeeDTO
> to employeeForm (Bean). Something like this:
>
>   When user click's "Edit Employee Form" link, an action
> (EditEmployeeAction) will be called. Which will do the following:
>
> 1. Fetch the employee information from database in employeeDTO.
> 2. Get the "handle" of EmployeeForm (ActionForm), lets say "employeeForm"
> 3. BeanUtils.copyProperties(employeeForm, employeeDTO)
> 4. return mapping.findForward("editMode");
>
>   I'm not sure whether this approach will work or not? And whether I have
> to
> make seprate JSP's for 1st time fill up (employeeForm.jsp) and edit mode (
> employeeFormEdit.jsp). If this the case, then I guess, I've to make
> EmployeeFormEdit.java  (ActionForm) as well.
>
>   It will be great if anybody could help me here.
>
> Thanks in advance.
>
> Bye,
> Viki.
>
>


--
Rick

Reply via email to