I know this is a bit late...but.

Here is a simple tag file, that is not Stripes specific.

<%@tag description="Executes the body if user is in the list of roles." 
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>

<%@attribute name="roles" required="true" description="Comma seperated list of 
roles"%>

<c:set var="ok" value="N"/>

<c:choose>
    <c:when test="${empty roles}">
        <c:set var="ok" value="Y"/>
    </c:when>
    <c:when test="${!empty roles}">
        <c:forEach items="${roles}" var="role">
            <%
            String myrole = (String)jspContext.findAttribute("role");
            if (request.isUserInRole(myrole)) {
            %>
            <c:set var="ok" value="Y"/>
            <% } %>
        </c:forEach>
    </c:when>
</c:choose>

<c:if test="${ok == 'Y'}">
    <jsp:doBody/>
</c:if>

It relies on the stock ServletRequest.isUserInrole routine to check membership, 
but you can use whatever you want there.

It also relies the capability of the c:forEach tag to take a comma separated 
list as an argument, and iterate across that.

You can easily use the tag in something like a JSP:

<ul>
    <li>Page 1</li>
    <li>Page 2</li>
    <t:inrole roles="ADMIN">
        <li>Admin Page</li>
    </t:inrole>
    <li>Page 3</li>
</ul>

Regards,

Will Hartung


On Mar 15, 2012, at 10:16 AM, Charles Yang wrote:

> Hi Stripes Community,
> 
> I am moving a PHP Web App to Java based framework. I have look at Apache Click
> and like it a lot. But coming from an Action oriented framework, I would like 
> to
> take a serious look at Stripes. I was wondering is there an example to create
> dynamic multi-level navigation menu based on User's roles?
> 
> Charles
> 
> 
> ------------------------------------------------------------------------------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here 
> http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to