Denis Hanson wrote:
> Hi all,
>
> I am starting to move our existing web application to the struts framework
> and would like to ask a design question.
>
> Here's my problem. After logon, the application user is forwarded to one of
> three screens - sysadmin, admin, user. The screen used is determined by the
> user's role. (The three screens have no commonality, so I don't think I can
> use the one <forward name="success".../> action attrubute shown in the
> example application.)
>
> I'm looking for some way to define the various paths in struts-config.xml so
> that the logon action class doesn't have hardcoded paths to the three
> role-based screens.
>
> Do I need to create my own ActionMapping class and add additional <forward
> name=/> entries, or is there some other way to do this?
>
Because we're talking about "what does the logon action forward to", you won't
need any additional action definitions. However, you might want some additional
forwards defined. For concreteness, let's assume that your three roles are
named "admin", "manager", and "user".
One approach to this would be to define, nested within the <action> element for
the login action, some forwards that are specific to only this action:
<struts-config>
...
<action-mappings>
...
<action path="/login" type="com.mycompany.mypackage.LoginAction">
<forward name="admin" path="/adminMainMenu.jsp"/>
<forward name="manager" path="/customerMainMenu.jsp"/>
<forward name="user" path="/usrMainMenu.jsp"/>
</action>
...
</action-mappings>
...
</struts-config>
In this scenario, you can do the following at the end of the login action:
String role = ... look up the role for this user ...
return (mapping.findForward(role));
to forward control to the menu for your user, without the action having to know
what the JSP page name is -- only the role name.
In the example above, the forwards "admin", "manager", and "user" are defined
locally for this particular action, and are not visible to any other action.
You can also define global forwards by nesting them in the <global-forwards>
section instead. When the findForward() method is executed, it searches first
in the local forwards for this particular action, and then in the global
forwards.
>
> Thanks,
>
> Denis Hanson
Craig McClanahan