Hi again, firstly You should read about OGNL basics because You are using it, then if You write <s:if test="canEditCustomer"> it works, why?, because struts is treating it like a regular getter, so it adds get and makes can to camel case Can and in result it searches for getCanEditCustomer() method, and it finds it in action. It is a general shortcut for dealing with fields which has getters and setters.
Now when You write <s:if test="canEditCustomer()"> struts sees this () at the end and it searches for canEditCustomer() method and of course it's not finding it anywhere. And last the method should be isCanEditCustomer(), but that is just my habbit. Also keep in mind what Wes was writing about, hidding a link is not suficient. Best greetings, Paweł Wielgus. 2009/9/23 Dennis Atkinson <dennisatkinson...@yahoo.com>: > 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 <w...@wantii.com> > To: Struts Users Mailing List <user@struts.apache.org> > 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. > > -Wes > > 2009/9/23 Paweł Wielgus <poulw...@gmail.com>: >> 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 <dennisatkinson...@yahoo.com>: >>> 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: user-unsubscr...@struts.apache.org >> For additional commands, e-mail: user-h...@struts.apache.org >> >> > > > > -- > Wes Wannemacher > > Head Engineer, WanTii, Inc. > Need Training? Struts, Spring, Maven, Tomcat... > Ask me for a quote! > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org