You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Steve Stair <st...@rrc.state.tx.us> on 2003/03/25 01:49:19 UTC

Adding ActionErrors in one tile to be displayed in another

I've got the following in a tiles layout file.
It checks for the user (in a user credential in the session) having
rights set in the tiles config file.
If the user does not have the required rights, they are sent back to
the home page.

<%-- Make the tiles "rightsRequired" variable available in the current
scope --%>
<tiles:useAttribute name="rightsRequired"
classname="java.lang.String"/>
<%-- Are any "rightsRequired"? --%>
<logic:notEqual name="rightsRequired" value="">
    <%-- Does the user NOT have the required rights? --%>
    <rights:notHasRights rights="<%= rightsRequired %>">
        <%-- Redirect to the home page --%>
        <logic:redirect forward="home"/>
   </rights:notHasRights>
</logic:notEqual>


What I would like to do, is cause an error message to be output when
this occurs.
I tried something like this, but it doesn't work.  Maybe every tile has
a different request object?

<%-- Make the tiles "rightsRequired" variable available in the current
scope --%>
<tiles:useAttribute name="rightsRequired"
classname="java.lang.String"/>
<%-- Are any "rightsRequired"? --%>
<logic:notEqual name="rightsRequired" value="">
    <%-- Does the user NOT have the required rights? --%>
    <rights:notHasRights rights="<%= rightsRequired %>">
        <%-- Put a message into the request for the next page to
display --%>
<%
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new
ActionError("error.rights"));
request.setAttribute(Action.ERROR_KEY, errors);
%>
        <%-- Redirect to the home page --%>
        <logic:redirect forward="home"/>
   </rights:notHasRights>
</logic:notEqual>


I've tried putting the error message in the session, instead of the
request,
and while that works, I'd have to go and remove the error or it sticks
around
to be displayed on every page :P

Is there another way to do this?


--
Steve Stair
Steve.Stair@rrc.state.tx.us


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org