You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Asleson, Ryan" <Ry...@biworldwide.com> on 2011/07/21 14:36:42 UTC

OGNL Problems During Struts2 Upgrade

Hello,

We are attempting to upgrade our application from Struts2 version 2.0.11.2 to the current version, 2.2.3.  As part of the upgrade, OGNL was upgraded from version 2.7.3 to version 3.0.1.

Our JSPs make use of OGNL to call static methods on classes to help with formatting.  Here's an example:

<s:property value="@com.example.DateUtils@toDate(promotion.startDate)" />

The DateUtils class has a static toDate method that takes in the passed in promotion.startDate object (which is likely a java.sql.Date) and converts it to a java.util.Date.  It does that so that s:property can properly and uniformly format the date for display.

This had worked before the upgrade from 2.0.11.2 to 2.2.3.  After the upgrade, it no longer works and the s:property tag doesn't output anything.  I put some logging statements in the toDate method and it looks like the toDate method is never being called in the first place.

One thing to note is that the DateUtils has two overloaded static toDate methods:  one that takes a String, and the other that takes a Date (or one of its subclasses).  This doesn't seem to make any difference as I've tried changing the method name (and the corresponding OGNL expression) and it still failed to work.

On this page:

http://struts.apache.org/2.2.3/docs/version-notes-211.html

I see this note in the "Backward compatibility issues with previous versions" section:

OGNL method calls like "text(key)" now invoke "text(String)" instead of "getText(String)". This affects method calls only, not properties. Some OGNL expressions may need to be updated.

I'm wondering if this is what is affecting me?  If so, how do I update the OGNL expression so that it works?  I've tried a few things like adding #attr. or simply # to the front of "promotion.startDate" but that didn't seem to work.

Any help is greatly appreciated.  Thank you!!!!

-Ryan



Ryan Asleson | Application Architect
BI | Technology Solutions Group
www.biworldwide.com<http://www.biworldwide.com>

Please consider the environment before printing.


This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

Re: OGNL Problems During Struts2 Upgrade

Posted by Dave Newton <da...@gmail.com>.
(Or struts.xml, the preferred mechanism AFAIK).

On Thursday, July 21, 2011, Jason Pyeron <jp...@pdinc.us> wrote:
>> -----Original Message-----
>> From: Asleson, Ryan
>> Sent: Thursday, July 21, 2011 8:37
>> To: user@struts.apache.org
>> Subject: [struts-user] OGNL Problems During Struts2 Upgrade
>>
>>
>> Hello,
>>
>> We are attempting to upgrade our application from Struts2
>> version 2.0.11.2 to the current version, 2.2.3.  As part of
>> the upgrade, OGNL was upgraded from version 2.7.3 to version 3.0.1.
>
> Not sure about the 2.0 upgrade path, will defer to someone else.
>
>>
>> Our JSPs make use of OGNL to call static methods on classes
>> to help with formatting.  Here's an example:
>>
>> <s:property
>> value="@com.example.DateUtils@toDate(promotion.startDate)" />
>>
>
> Can you check you struts.properties for:
>
> struts.ognl.allowStaticMethodAccess=true
>
>> The DateUtils class has a static toDate method that takes in
>> the passed in promotion.startDate object (which is likely a
>> java.sql.Date) and converts it to a java.util.Date.  It does
>> that so that s:property can properly and uniformly format the
>> date for display.
>>
>> This had worked before the upgrade from 2.0.11.2 to 2.2.3.
>> After the upgrade, it no longer works and the s:property tag
>> doesn't output anything.  I put some logging statements in
>> the toDate method and it looks like the toDate method is
>> never being called in the first place.
>>
>> One thing to note is that the DateUtils has two overloaded
>> static toDate methods:  one that takes a String, and the
>> other that takes a Date (or one of its subclasses).  This
>> doesn't seem to make any difference as I've tried changing
>> the method name (and the corresponding OGNL expression) and
>> it still failed to work.
>>
>> On this page:
>>
>> http://struts.apache.org/2.2.3/docs/version-notes-211.html
>>
>> I see this note in the "Backward compatibility issues with
>> previous versions" section:
>>
>> OGNL method calls like "text(key)" now invoke "text(String)"
>> instead of "getText(String)". This affects method calls only,
>> not properties. Some OGNL expressions may need to be updated.
>>
>> I'm wondering if this is what is affecting me?  If so, how do
>> I update the OGNL expression so that it works?  I've tried a
>> few things like adding #attr. or simply # to the front of
>> "promotion.startDate" but that didn't seem to work.
>
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> -                                                               -
> - Jason Pyeron                      PD Inc. http://www.pdinc.us -
> - Principal Consultant              10 West 24th Street #100    -
> - +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -
> -                                                               -
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> This message is copyright PD Inc, subject to license 20080407P00.
>
>
>
>
> ---------------------------------------------------------------------
> 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: [struts-user] OGNL Problems During Struts2 Upgrade

Posted by Jason Pyeron <jp...@pdinc.us>.
> -----Original Message-----
> From: Asleson, Ryan 
> Sent: Thursday, July 21, 2011 8:37
> To: user@struts.apache.org
> Subject: [struts-user] OGNL Problems During Struts2 Upgrade
> 
> 
> Hello,
> 
> We are attempting to upgrade our application from Struts2 
> version 2.0.11.2 to the current version, 2.2.3.  As part of 
> the upgrade, OGNL was upgraded from version 2.7.3 to version 3.0.1.

Not sure about the 2.0 upgrade path, will defer to someone else.

> 
> Our JSPs make use of OGNL to call static methods on classes 
> to help with formatting.  Here's an example:
> 
> <s:property 
> value="@com.example.DateUtils@toDate(promotion.startDate)" />
> 

Can you check you struts.properties for:

struts.ognl.allowStaticMethodAccess=true

> The DateUtils class has a static toDate method that takes in 
> the passed in promotion.startDate object (which is likely a 
> java.sql.Date) and converts it to a java.util.Date.  It does 
> that so that s:property can properly and uniformly format the 
> date for display.
> 
> This had worked before the upgrade from 2.0.11.2 to 2.2.3.  
> After the upgrade, it no longer works and the s:property tag 
> doesn't output anything.  I put some logging statements in 
> the toDate method and it looks like the toDate method is 
> never being called in the first place.
> 
> One thing to note is that the DateUtils has two overloaded 
> static toDate methods:  one that takes a String, and the 
> other that takes a Date (or one of its subclasses).  This 
> doesn't seem to make any difference as I've tried changing 
> the method name (and the corresponding OGNL expression) and 
> it still failed to work.
> 
> On this page:
> 
> http://struts.apache.org/2.2.3/docs/version-notes-211.html
> 
> I see this note in the "Backward compatibility issues with 
> previous versions" section:
> 
> OGNL method calls like "text(key)" now invoke "text(String)" 
> instead of "getText(String)". This affects method calls only, 
> not properties. Some OGNL expressions may need to be updated.
> 
> I'm wondering if this is what is affecting me?  If so, how do 
> I update the OGNL expression so that it works?  I've tried a 
> few things like adding #attr. or simply # to the front of 
> "promotion.startDate" but that didn't seem to work.

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                      PD Inc. http://www.pdinc.us -
- Principal Consultant              10 West 24th Street #100    -
- +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.

 


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


Re: OGNL Problems During Struts2 Upgrade

Posted by "Asleson, Ryan" <Ry...@biworldwide.com>.
I enabled static method access by adding this to struts.xml:

<constant name="struts.ognl.allowStaticMethodAccess" value="true" />

Thanks to the direction I found here under the "Accessing static properties" section:

http://struts.apache.org/2.2.3/docs/ognl-basics.html

And it now works!!!  Thank you!!!!

On Jul 21, 2011, at 7:42 AM, Asleson, Ryan wrote:


How do I enable static method access?  Is that through OGNL or Struts2?

I don't know why the default formatting tags aren't being used.  Probably because the app uses a custom content management system but I don't know.  There are over 100 files that use this method for formatting dates and I really don't want to change them all!


On Jul 21, 2011, at 7:39 AM, Dave Newton wrote:

Did you enable static method access? The default may have changed. (Is
there a reason the default formatting tags aren't being used? Or the
JSTL format tags?)

Dave

On Thursday, July 21, 2011, Asleson, Ryan <Ry...@biworldwide.com>> wrote:

Hello,

We are attempting to upgrade our application from Struts2 version 2.0.11.2 to the current version, 2.2.3.  As part of the upgrade, OGNL was upgraded from version 2.7.3 to version 3.0.1.

Our JSPs make use of OGNL to call static methods on classes to help with formatting.  Here's an example:

<s:property value="@com.example.DateUtils@toDate(promotion.startDate)" />

The DateUtils class has a static toDate method that takes in the passed in promotion.startDate object (which is likely a java.sql.Date) and converts it to a java.util.Date.  It does that so that s:property can properly and uniformly format the date for display.

This had worked before the upgrade from 2.0.11.2 to 2.2.3.  After the upgrade, it no longer works and the s:property tag doesn't output anything.  I put some logging statements in the toDate method and it looks like the toDate method is never being called in the first place.

One thing to note is that the DateUtils has two overloaded static toDate methods:  one that takes a String, and the other that takes a Date (or one of its subclasses).  This doesn't seem to make any difference as I've tried changing the method name (and the corresponding OGNL expression) and it still failed to work.

On this page:

http://struts.apache.org/2.2.3/docs/version-notes-211.html

I see this note in the "Backward compatibility issues with previous versions" section:

OGNL method calls like "text(key)" now invoke "text(String)" instead of "getText(String)". This affects method calls only, not properties. Some OGNL expressions may need to be updated.

I'm wondering if this is what is affecting me?  If so, how do I update the OGNL expression so that it works?  I've tried a few things like adding #attr. or simply # to the front of "promotion.startDate" but that didn't seem to work.

Any help is greatly appreciated.  Thank you!!!!

-Ryan



Ryan Asleson | Application Architect
BI | Technology Solutions Group
www.biworldwide.com<http://www.biworldwide.com>

Please consider the environment before printing.


This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

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


Ryan Asleson | Application Architect
BI | Technology Solutions Group
www.biworldwide.com<http://www.biworldwide.com>

Please consider the environment before printing.


This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

Ryan Asleson | Application Architect
BI | Technology Solutions Group
www.biworldwide.com<http://www.biworldwide.com>

Please consider the environment before printing.


This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

Re: OGNL Problems During Struts2 Upgrade

Posted by "Asleson, Ryan" <Ry...@biworldwide.com>.
How do I enable static method access?  Is that through OGNL or Struts2?

I don't know why the default formatting tags aren't being used.  Probably because the app uses a custom content management system but I don't know.  There are over 100 files that use this method for formatting dates and I really don't want to change them all!


On Jul 21, 2011, at 7:39 AM, Dave Newton wrote:

Did you enable static method access? The default may have changed. (Is
there a reason the default formatting tags aren't being used? Or the
JSTL format tags?)

Dave

On Thursday, July 21, 2011, Asleson, Ryan <Ry...@biworldwide.com>> wrote:

Hello,

We are attempting to upgrade our application from Struts2 version 2.0.11.2 to the current version, 2.2.3.  As part of the upgrade, OGNL was upgraded from version 2.7.3 to version 3.0.1.

Our JSPs make use of OGNL to call static methods on classes to help with formatting.  Here's an example:

<s:property value="@com.example.DateUtils@toDate(promotion.startDate)" />

The DateUtils class has a static toDate method that takes in the passed in promotion.startDate object (which is likely a java.sql.Date) and converts it to a java.util.Date.  It does that so that s:property can properly and uniformly format the date for display.

This had worked before the upgrade from 2.0.11.2 to 2.2.3.  After the upgrade, it no longer works and the s:property tag doesn't output anything.  I put some logging statements in the toDate method and it looks like the toDate method is never being called in the first place.

One thing to note is that the DateUtils has two overloaded static toDate methods:  one that takes a String, and the other that takes a Date (or one of its subclasses).  This doesn't seem to make any difference as I've tried changing the method name (and the corresponding OGNL expression) and it still failed to work.

On this page:

http://struts.apache.org/2.2.3/docs/version-notes-211.html

I see this note in the "Backward compatibility issues with previous versions" section:

OGNL method calls like "text(key)" now invoke "text(String)" instead of "getText(String)". This affects method calls only, not properties. Some OGNL expressions may need to be updated.

I'm wondering if this is what is affecting me?  If so, how do I update the OGNL expression so that it works?  I've tried a few things like adding #attr. or simply # to the front of "promotion.startDate" but that didn't seem to work.

Any help is greatly appreciated.  Thank you!!!!

-Ryan



Ryan Asleson | Application Architect
BI | Technology Solutions Group
www.biworldwide.com<http://www.biworldwide.com>

Please consider the environment before printing.


This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

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


Ryan Asleson | Application Architect
BI | Technology Solutions Group
www.biworldwide.com<http://www.biworldwide.com>

Please consider the environment before printing.


This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

Re: OGNL Problems During Struts2 Upgrade

Posted by Dave Newton <da...@gmail.com>.
Did you enable static method access? The default may have changed. (Is
there a reason the default formatting tags aren't being used? Or the
JSTL format tags?)

Dave

On Thursday, July 21, 2011, Asleson, Ryan <Ry...@biworldwide.com> wrote:
>
> Hello,
>
> We are attempting to upgrade our application from Struts2 version 2.0.11.2 to the current version, 2.2.3.  As part of the upgrade, OGNL was upgraded from version 2.7.3 to version 3.0.1.
>
> Our JSPs make use of OGNL to call static methods on classes to help with formatting.  Here's an example:
>
> <s:property value="@com.example.DateUtils@toDate(promotion.startDate)" />
>
> The DateUtils class has a static toDate method that takes in the passed in promotion.startDate object (which is likely a java.sql.Date) and converts it to a java.util.Date.  It does that so that s:property can properly and uniformly format the date for display.
>
> This had worked before the upgrade from 2.0.11.2 to 2.2.3.  After the upgrade, it no longer works and the s:property tag doesn't output anything.  I put some logging statements in the toDate method and it looks like the toDate method is never being called in the first place.
>
> One thing to note is that the DateUtils has two overloaded static toDate methods:  one that takes a String, and the other that takes a Date (or one of its subclasses).  This doesn't seem to make any difference as I've tried changing the method name (and the corresponding OGNL expression) and it still failed to work.
>
> On this page:
>
> http://struts.apache.org/2.2.3/docs/version-notes-211.html
>
> I see this note in the "Backward compatibility issues with previous versions" section:
>
> OGNL method calls like "text(key)" now invoke "text(String)" instead of "getText(String)". This affects method calls only, not properties. Some OGNL expressions may need to be updated.
>
> I'm wondering if this is what is affecting me?  If so, how do I update the OGNL expression so that it works?  I've tried a few things like adding #attr. or simply # to the front of "promotion.startDate" but that didn't seem to work.
>
> Any help is greatly appreciated.  Thank you!!!!
>
> -Ryan
>
>
>
> Ryan Asleson | Application Architect
> BI | Technology Solutions Group
> www.biworldwide.com<http://www.biworldwide.com>
>
> Please consider the environment before printing.
>
>
> This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

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