>>> Here is the work flow:
>>>
>>> 1. select user from list
>>>     - executes SelectUserAction that places UserBean in request scope.
>>>     - forwards to edituser.jsp.
>>> 2. Populate form that is in edituser.jsp from UserBean
>>>     - that form has action mapping to UpdateUserAction.
>>> 3. Submit form (Update)
>>>     - UserForm gets populated and then it's validated by struts by
calling
>>>        validate method.
>>>     - If validation fails then  go back to edituser.jsp and the problem
>>>       arises: there is not anymore UserBean in request scope, because
>>>       SelectUserAction is responsible of that and it does not get
>>>       executed, so I get error: No xxx bean in scope null.
>>>
>>> So how do I write that form so I can populate it automatically? I mean
>>> that what code I should put in SelectUserAction so I can use tag like
>>> this:
>>
>> I got it to work. Thanks for everyone who replied to this issue!
>>
>
> Would you care to elaborate on your solution?
>

Ok here it goes. Instead of populating custom UserBean I populate
UserForm Bean in EditUserAction. The form is the same that is also
used in UpdateUserAction and InsertUserAction. I know that struts
guidelines say that reuse you action classes, but I like separating these
different actions in different action classes because I'm quite new to
this Java World and I'm not using EJBs. This works for me. If you
are planning bigger application then it is recommended to use EJBs,
but the timeframe in this project is so tight so I have no time to learn
all those fancy Java APIs and Patterns.

My Mappings looks like this:

    <form-beans>
        <form-bean name="UserForm"
                   type="com.projectcast.sfundm.UserForm"/>
    </form-beans>

    <action-mappings>
        <action path="/userlist"
                type="com.projectcast.sfundm.UserListAction"
                name="UserForm"
               scope="request"
            validate="false">
            <forward name="success"
                     path="/WEB-INF/web/userlist.jsp"/>
            <!-- this is redundant as it forwards to same place
                    as success, but it is here so I can change it if
                    I want and Action class remains unchanged   -->
            <forward name="failure"
                     path="/WEB-INF/web/userlist.jsp"/>
        </action>
        <action path="/edituser"
                type="com.projectcast.sfundm.UserSelectAction"
                name="UserForm"
               scope="request"
            validate="false">
            <forward name="success"
                     path="/WEB-INF/web/edituser.jsp"/>
        </action>
        <action path="/updateuser"
                type="com.projectcast.sfundm.UserUpdateAction"
                name="UserForm"
               scope="request"
               input="/edituser.do"
            validate="true">
            <forward name="success"
                     path="/userlist.do"
                 redirect="true"/>
            <forward name="cancel"
                     path="/userlist.do"
                 redirect="true"/>
        </action>
        <action path="/insertuser"
                type="com.projectcast.sfundm.UserInsertAction"
                name="UserForm"
               scope="request"
               input="/userlist.do"
            validate="true">
            <forward name="success"
                     path="/userlist.do"
                 redirect="true"/>
        </action>
        <action path="/deleteuser"
                type="com.projectcast.sfundm.UserDeleteAction"
               scope="request"
               input="/userlist.do"
            validate="false">
            <forward name="success"
                     path="/userlist.do"/>
        </action>
    </action-mappings>

Pretty weird, huh!

Reply via email to