You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Dowson <jl...@gmail.com> on 2010/07/02 11:13:33 UTC

Weird problem with struts tags

I have an action class that has the following method

   public WebUser getAuthenticatedUser() ....

The WebUser class has the following methods:

  public Employee getEmployee()....
  public boolean isEmployee()...

and the WebUser class has the following method

 public boolean isWorkgroupEnable()....

In a jsp I use the following tag:
	<s:if test="AuthenticatedUser.Employee.workgroupEnable">

Will this call the getEmployee() method or the isEmployee() method?

I ask because this code used to work but is now causing problems. The weird thing is that the behaviour seems to be different depending upon the environment.
I have inserted the following debug statements to try and find out what is happening:

console.log('Authenticated user: <s:property value="AuthenticatedUser.displayName"/>');
console.log('Employee is: <s:property value="AuthenticatedUser.employee"/>');  // lower case e
console.log('Employee is: <s:property value="AuthenticatedUser.Employee"/>'); // upper case E
console.log('Employee name is: <s:property value="AuthenticatedUser.Employee.name"/>');
console.log('Employee name is: <s:property value="AuthenticatedUser.employee.name"/>');
console.log('**Code uses: Is workgroups enabled: <s:property value="AuthenticatedUser.Employee.workgroupEnable"/>');

On my dev environment (Mac OS X), this produces the following output:
	Authenticated user: Insurer Admin			-- as expected
	Employee is: true							-- isEmployee() method called
	Employee is: true							-- isEmployee() method called
	Employee name is:				                -- isEmployee() method called
	Employee name is:					        -- isEmployee() method called
	**Code uses: Is workgroups enabled: 
which indicates that the isEmployee() method is being called.
However, the exact same war file dropped into our integration server running Gnu Linux gives the following:
	Authenticated user: Insurer Admin				-- as expected
	Employee is: true								-- isEmployee() method called
	Employee is: idas.chox.core.model.Insurer@3	-- getEmployee() method called
	Employee name is: RSD						-- getEmployee() method called
	Employee name is:							-- isEmployee() method called
	**Code uses: Is workgroups enabled: true
which indicates that the isEmployee method is called when a lower case letter is used, and the getEmployee() method when the uppercase letter is used.

Does anyone have any idea what is causing this different behaviour for the same code?

This has now been driving me crazy for several days, so any help much appreciated. Up until a few days ago, the code was also working as expected on my local (mac os x) environment.

John.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Weird problem with struts tags

Posted by John Dowson <jl...@gmail.com>.
Thanks Greg (and Ken).  I appreciate the comments and will get around to updating this code at some point. However I believe these errors to be a symptom of a deeper problem as this code WAS - and still is on some servers - working. I am also getting other strange errors in code which was previously working (such as hibernate PropertyAccessException). I can check out older released versions of the app and they still work on the production and integration servers but I get these errors (and more) on my development machine. I am therefore trying to find out what has changed to produce these errors, and why they are only produced in certain environments.

The same versions of OGNL (ognl-2.6.11.jar) is being used in both environments. As I said, the exact same war file dropped into works on one server but not on another. Further more, it used to work in the environments in which it is now broken. There has also been no java/tomcat/etc updates (that I am aware of)  that could have caused this. I am completely flummoxed by this!
Any further help much appreciated.


On 2 Jul 2010, at 19:46, Greg Lindholm wrote:

> Your basic problem is that having both getEmployee() and isEmployee()
> is a violation of the JavaBeans "standard" so you are asking for
> trouble. The Employee property is not a boolean so you really should
> rename isEmployee() to something else (maybe isTypeEmployee()).  If
> you can't do this then you shouldn't use the OGNL dot style syntax,
> instead use explicit java method call style naming like Ken suggested.
> 
> WRT the upper vs lower case 'E': The correct use is lowercase 'e'.  I
> have heard reports that different versions of OGNL are tolerant of
> different cases but you may be causing it to do extra work and slowing
> down the evaluation of the expression.  Better to just stick with the
> expected leading lowercase letter.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Weird problem with struts tags

Posted by Greg Lindholm <gr...@gmail.com>.
Your basic problem is that having both getEmployee() and isEmployee()
is a violation of the JavaBeans "standard" so you are asking for
trouble. The Employee property is not a boolean so you really should
rename isEmployee() to something else (maybe isTypeEmployee()).  If
you can't do this then you shouldn't use the OGNL dot style syntax,
instead use explicit java method call style naming like Ken suggested.

WRT the upper vs lower case 'E': The correct use is lowercase 'e'.  I
have heard reports that different versions of OGNL are tolerant of
different cases but you may be causing it to do extra work and slowing
down the evaluation of the expression.  Better to just stick with the
expected leading lowercase letter.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Weird problem with struts tags

Posted by Ken <ke...@aerose.com>.
I think you can just spell out the method:
<s:if test="AuthenticatedUser.getEmployee().workgroupEnable">


On Fri, 2010-07-02 at 10:13 +0100, John Dowson wrote:

> <s:if test="AuthenticatedUser.Employee.workgroupEnable">