views:

385

answers:

1

Suppose that I am using the Struts 2 iterate tag on a list of objects. Each object has a property called creatorUserId.

I would like to compare the creatorUserId with the Id number of the currently logged in user.

How do I do this with Spring Security and Struts 2 in the JSP page?

<security:authentication property="principal.userID" /> displays the current user's ID number

<s:property value="creatorUserId" /> displays the current iterator item's creatorUserId.

I would like to do:

<s:if test="%{creatorUserId == <security:authentication property='principal.userID' />}">

but it is not a legal expression.

Can anyone help with the syntax?

A: 

I'm not familiar with Struts, but <security:authentication> has a var attribute to export its result as a named context attribute:

<security:authentication var = "userId" property = "principal.userID" /> 
<c:if test = "%{creatorUserId == userId}"> 
axtavt