Stephen:

Your suggestions worked beautifully. I'm definetely starting to dig this
struts stuff. It makes the work a lot easier once it starts to make sense.

Take care,

**********************************************
Juan Alvarado
Internet Developer -- Manduca Management
(786)552-0504
[EMAIL PROTECTED]
AOL Instant Messenger: [EMAIL PROTECTED]

-----Original Message-----
From: Stephen Owens [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 12, 2001 11:30 AM
To: Struts Users Mailing List
Subject: RE: Help with an action


My first guess is....

You need to rewrite your action definition from
    <action     path="/loadUserIntoSessionAction"
            type="com.manduca.protrack.LoadUserIntoSessionAction"
            scope="request">
to
    <action     path="/loadUserIntoSessionAction"
            type="com.manduca.protrack.LoadUserIntoSessionAction"
            name="editUserForm"
            scope="request">

then in your perform method instead of
        EditUserForm euf = new EditUserForm();

you would
        if ( actionForm instanceof EditUserForm )
                EditUserForm euf = (EditUserForm)actionForm;
        else
                throw Incredibly descriptive and useful exception

and make sure that editUserForm is referenced from your action for
editing the data as well. That way your populating and using the same
object automatically.

Hope this helps,

Stephen

-----Original Message-----
From: Juan Alvarado (Struts List) [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 12, 2001 11:23 AM
To: Struts Users Mailing List
Subject: RE: Help with an action


Stephen:

I followed your steps but I'm having some problems pre-populating the
form.

Let me give you some more details and hopefully you can help me out
here.

I have a page that lists a set of users with links to each user's
details.
The action on the link is set up as follows in struts-config.xml:

<!--   LoadUserIntoSessionAction action -->
    <action     path="/loadUserIntoSessionAction"
            type="com.manduca.protrack.LoadUserIntoSessionAction"
            scope="request">
                <forward name="success" path="/editUser.jsp"/>
                <forward name="failure" path="/mainMenu.jsp"    />
    </action>

My perform method in LoadUserIntoSessionAction looks like this:

UserListBean userList =
(UserListBean)servlet.getServletContext().getAttribute("userList");
        String userRequested = request.getParameter("user");
        EditUserForm euf = new EditUserForm();

        try{
                //get a copy of the userBean we want to work on
                UserBean user = userList.getUser(userRequested);
                if( user == null ){
                        return mapping.findForward("failure");
                }
                else{
                        PropertyUtils.copyProperties(euf, user);
                        return mapping.findForward("success");
                }
        }
        catch(InvocationTargetException ite){
                debug("LoadUserUntoSessionAction.perform --
InvocationTargetException ite
" + ite.toString());
                return mapping.findForward("failure");
        }
        catch(NoSuchMethodException nsme){
                debug("LoadUserUntoSessionAction.perform --
NoSuchMethodException nsme " +
nsme.toString());
                return mapping.findForward("failure");
        }
        catch(IllegalAccessException iae){
                debug("LoadUserUntoSessionAction.perform --
IllegalAccessException iae " +
iae.toString());
                return mapping.findForward("failure");
        }

As you can see, the user does not interact with a form to get to the
edit
user page. They just click on a link and it takes them there.

I do have an edit user form defined in struts-config.xml:

<!-- Edit user form bean -->
    <form-bean      name="editUserForm"
                    type="com.manduca.protrack.EditUserForm"/>
  </form-beans>

So basically what is happening is that I can get to the page where you
would
edit the user's details, but the form is not being pre-populated. I
looked
at some debug code, and my euf(EditUserForm) object is receiving all the
properties from the user bean in PropertyUtils.copyProperties(euf,
user); .
I get the feeling I'm missing something very basic here, so if you
happen to
catch it, by all means please let me know.

Thanks for your help.


**********************************************
Juan Alvarado
Internet Developer -- Manduca Management
(786)552-0504
[EMAIL PROTECTED]
AOL Instant Messenger: [EMAIL PROTECTED]

-----Original Message-----
From: Stephen Owens [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 12, 2001 9:55 AM
To: Struts Users Mailing List
Subject: RE: Help with an action


Juan,

I'll give you a few quick ideas and if you have trouble with particular
pieces of it you can write back with more detailed questions.

1) Use an html:link tag from the Struts html taglib to generate a link
to your action that includes information that identifies which user was
chosen (userID? e-mail? whatever your primary key is)

2) In the action load the correct bean using the identifying information
that will be given as a parameter to the action.

3) Then, still in the action use the BeanUtils methods to populate the
properties from your bean into the form object. This works really well
if the property names are identical between your model bean and your
form bean. This assumes that your loadUserIntoSessionAction is defined
to use your user form bean, which causes it to automatically create the
form bean object for you and provide it as an argument to your action.

4) Now forward to the jsp that actually displays the user information
for editing. Make sure that the action of the form is defined in
struts-config and refers to the same form as your
loadUserIntoSessionAction, that way your form bean will automatically be
preserved for you.

5) That's it, when you display your jsp form it should have all the
values prepopulated.

-----Original Message-----
From: Juan Alvarado (Struts List) [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 12, 2001 9:45 AM
To: Struts
Subject: Help with an action


Hello:

I have what some of you might think is a simple question. I have a page
that
displays me a list of users with links to each user's details. When a
link
is clicked the link sends a request to /loadUserIntoSessionAction. What
I
would like to do in that action is take the user's details which is
stored
in a bean and populate those values in the edit user form.

SO basically the user goes trough /loadUserIntoSessionAction there I
want to
populate my editUserForm which is of type
com.manduca.protrack.EditUserForm from the values in a bean called
UserBean
and then forward to the edit user page and have all the form fields
already
pre-populated.

If anyone can point me in the right direction, I would greatly
appreciated.

Thanks

**********************************************
Juan Alvarado
Internet Developer -- Manduca Management
(786)552-0504
[EMAIL PROTECTED]
AOL Instant Messenger: [EMAIL PROTECTED]


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to