kitokid
kitokid

Reputation: 3117

check property value in struts2

I have currently login User object (userId,organisationId,etc.. ) stored in session by using like this.

session.setAttribute("user", LoginUser);

Where my LoginUser is User object with detail information.

In my next jsp page, I want to check the user's organisationId by calling from Session.

<s:property value="%{#session.user.organisationId}"/>

How can I check the organisationId in property value is 0 or etc., and do things according to various IDs?

How can I check using c:choose?

Thanks.

Upvotes: 0

Views: 1853

Answers (3)

Quaternion
Quaternion

Reputation: 10458

<s:if test="#session.user.organisationId == 0">
 <p>I'm Zero.</p>
</s:if>
<s:elseif test="#session.user.organisationId == 1">
 <p>I am One.</p>
</s:elseif>
<s:else>
    <p>I not either of these things.</p>
</s:else>

organisationId must be a numeric type.

Upvotes: 1

Buhake Sindi
Buhake Sindi

Reputation: 89169

Using JSTL, either <c:if> conditional tag:

<c:if test="${sessionScope.user.organisationId == 0}">

</c:if>

Or using <c:choose> conditional tag:

<c:choose>
    <c:when test="${sessionScope.user.organisationId == 0}">
        <!-- true -->
    </c:when>
    <c:otherwise>
        <!-- false -->
    </c:otherwise>
</c:choose>

Upvotes: 3

Jigar Joshi
Jigar Joshi

Reputation: 240860

<c:choose>
  <c:when test="${user.organizationId == 1}">
        <!-- do something -->
  </c:when>
  <c:otherwise>
        <!-- do something different -->
  </c:otherwise>
</c:choose>

Upvotes: 3

Related Questions