2
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
 <%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<body>
<s:iterator value="roleList">
    <s:if test="%{#userRole}=='Admin'}" >
        <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Manage Users <span class="caret"></span></a>
            <ul class="dropdown-menu" role="menu">
                <li><a href="adduser.jsp">Add User</a></li>
                <li class="divider"></li>
                 <li><a href="viewusers.jsp">View / Edit User</a></li>
            </ul>
    </li>
    </s:if>
    </s:iterator>

Here I want to check whether the user who has logged in is user or admin.If he/she is user I dont want to dsiplay one section in header section to that user which is Manage users but for Admin I want to display that block but I am unable to do so.Above is my code where userRole is my variable in which the role of the user is stored and roleList is the arraylist object in which the role value is added.So please help me or provide some links where I can study such examples and do accordingly.

  • 3
    `%{#userRole}=='Admin'}` Let's count. 1,2,3... something is missing or more than needed. – Aleksandr M May 03 '16 at 10:59
  • 3
    Besides what Aleksandr is hinting at, is `userRole` a property of the elements in `roleList` or is it the element itself? If the latter you're missing a `var="userRole"` in the iterator tag. Additionally, why are you iterating over a list instead of checking against a set? – Thomas May 03 '16 at 11:02

1 Answers1

1

I solved my problem by referring to this Link.It will surely help others in future .

Community
  • 1
  • 1