struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dennis Atkinson <>
Subject Re: Question about 'if' tag
Date Wed, 23 Sep 2009 21:52:23 GMT
I have gone through Pawel's example and it is not working for me.

Here is the iterator:

         <s:iterator value="allCustomers" id="iter" status="table_stat">

I created three methods in my action class:

public boolean getCanEditCustomer()
    return false ;

public boolean getCanEditCustomer(Integer anInt)
    return false ;

public boolean getCanEditCustomer(Customer aCustomer)
    return false ;

These are dummy methods just to see if everything will work.  I set an Eclipse breakpoint
on each return statement.  So in theory, Eclipse should stop on one of the statements whether
I pass in nothing, an integer, or a Customer object.

The results are:

<s:if test="canEditCustomer">              (This stops in the first method)
<s:if test="canEditCustomer()">            (This never stops)
<s:if test="canEditCustomer(5)">          (This never stops)
<s:if test="canEditCustomer(iter)">       (This never stops)

So it seems like no parameters are being passed in; in fact when I use the braces to indicate
no parameter, that doesn't work either.  

From: Wes Wannemacher <>
To: Struts Users Mailing List <>
Sent: Wednesday, September 23, 2009 4:20:33 PM
Subject: Re: Question about 'if' tag

In addition to what Pawel is saying, be careful that you also check
the 'canEditCustomer(target)' call in the target action since there is
nothing to stop someone from figuring out the URL pattern and editing
people they weren't intended to edit.


2009/9/23 Paweł Wielgus <>:
> Hi Dennis,
> You are nesting tags, it's not possible/permitted,
> what You should do is something like:
> <s:iterator value="..." id="iter"> or <s:iterator value="..." var="iter">
> ....
> <s:if test="user.canEditCustomer(iter)">
> Which simply is naming your iterator variable to "iter" and use it in if tag,
> depending on struts2 version it will be id or var.
> Best greetings,
> Paweł Wielgus.
> 2009/9/23 Dennis Atkinson <>:
>> Hi all.
>> In my Struts2 application, I have a collection of Customer objects, and various users
have the rights to edit some of them and not others.  I have created a Struts iterator tag,
and in the iterator, I put the various Customer attributes into an HTML table.  All this works.
>> In one cell of the table, I have the string "Edit", and if it's clicked, it goes
to another Action class to edit that particular Customer object.  All that works too.
>> What I want to do is only show the "Edit" string if the user has the right to edit
that Customer.  I'm trying to set a "<s:if" tag to do this, but I am sure I'm not doing
it right (because it's not working).
>> I am trying:
>> <s:if test="%{user.canEditCustomer(<s:property>)}">
>> hoping "property" is the current object in the iteration.  But whatever is happening,
this doesn't do what I hope it does.  Am I anywhere close to the right solution here?
>> Thanks,
>> Dennis
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message