You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by mraible <ma...@raibledesigns.com> on 2008/04/10 20:32:52 UTC

Re: How can I tell Struts 2 to throw/log exceptions for invalid OGNL Expressions

Following up months later as this has come up again now that 2.1 is close to
release. The current version does log messages for invalid properties, but
it doesn't blow up for invalid properties which is more of what I'm looking
for.

When I blogged about this[1], one of the responses was the following:



> When you are using freemarker as your result technology in struts2 you get
> great feedback on problems like this. This is not indicative of the whole
> framework -- just the result-type that you are using (probably jsp?)
> 

I tried FreeMarker this morning and discovered that the problem exists there
too. Grrr. I've experienced Struts 2 being eliminated as a web framework
candidate on a couple projects because of this. Kindof annoying. 

Matt

[1] http://raibledesigns.com/rd/entry/does_struts_2_suck


Ted Husted wrote:
> 
> Good point. Feel free to open a S2 JIRA ticket that cross-references
> XW-557 (since I'm not sure if its something we could do here or not)
> -- and feel even more free to submit a patch!
> 
> As usual, we are short of active volunteers, and we can always use a
> hand with the code!
> 
> -Ted.
> 
> On 9/6/07, mraible <ma...@raibledesigns.com> wrote:
>>
>> struts.devMode=true will catch setting invalid properties, but not
>> reading
>> from them. I want to be warned when a property/method doesn't exist. Or
>> in
>> the instance of calling stating methods with FQCN, I want to be made
>> aware
>> when I fat finger the package name. If I could use JSP's import and then
>> read from the package, that'd be even nicer. It's somewhat verbose to
>> call
>> FQ static methods. I suppose I could move the methods into my action, so
>> it's not too bad.
>>
>> Matt
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-tell-Struts-2-to-throw-log-exceptions-for-invalid-OGNL-Expressions-tp11659700p16612885.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: How can I tell Struts 2 to throw/log exceptions for invalid OGNL Expressions

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
mraible wrote:
> I realize it might be a major effort, but this seems to be a pretty big deal
> to me. Not for users that've already chosen Struts 2 as a web framework, but
> for folks evaluating Java Web Frameworks. The fact that Struts 2 is the
> *only* one that doesn't blow up on invalid properties makes it look pretty
> bad for evaluations. It's kindof like the old blank page you'd sometimes get
> with Tiles - you really have no idea what you did wrong and it can take
> quite some time to track it down if you don't know what's causing it.
>
> Matt
>   

Strongly agreed.  This issue does have a productivity cost.  I'll try to 
do more about it myself. 
I've committed an improvement for message resources 
(https://issues.apache.org/struts/browse/WW-2592).



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


Re: How can I tell Struts 2 to throw/log exceptions for invalid OGNL Expressions

Posted by mraible <ma...@raibledesigns.com>.


Jeromy Evans - Blue Sky Minds wrote:
> 
> Jeromy Evans wrote:
>> mraible wrote:
>>
>>>
>>> I tried FreeMarker this morning and discovered that the problem 
>>> exists there
>>> too. Grrr. I've experienced Struts 2 being eliminated as a web framework
>>> candidate on a couple projects because of this. Kindof annoying.
>>>   
>>
>> So what do you really want?  My guess here is that you invoked a 
>> struts tag and the tag swallowed the error and provided a default to 
>> the freemarker template.
>>
>>
> 
> On further thought I think this comes down to an interesting issue with 
> coupling between the view and the model.
> In struts2 the model is a ValueStack that consists of both a stack and 
> map (context).  OGNL is used to address properties or methods in that 
> model and it's a trivial for OGNL to log when it fails to match a 
> property or method.
> 
> In the view, Struts2 provides tags for jsp, ftl or velocity that 
> evaluate OGNL expressions to access the model.  More often that not the 
> tags fail silently if the expression was invalid or failed to evaluate 
> anything.  Herein lies the problem. 
> 
> If I were using FTL directly to access the value stack, as a developer I 
> could decide how to handle missing properties, blank properties or 
> default values with FTL's excellent error handling.  However, when I use 
> FTL to invoke a Struts2 tag I lose that benefit as the tag 
> implementations *transfer* properties into the FTL context. I think its 
> a flaw that Struts2 tags evaluate OGNL expressions themselves prior to 
> rendering the template.. 
> 
> A tag overhaul is well overdue (but major effort).  I've expressed other 
> concerns about the Struts2 tags (XWork Component and UIBean) on several 
> occasions already.
> 

I realize it might be a major effort, but this seems to be a pretty big deal
to me. Not for users that've already chosen Struts 2 as a web framework, but
for folks evaluating Java Web Frameworks. The fact that Struts 2 is the
*only* one that doesn't blow up on invalid properties makes it look pretty
bad for evaluations. It's kindof like the old blank page you'd sometimes get
with Tiles - you really have no idea what you did wrong and it can take
quite some time to track it down if you don't know what's causing it.

Matt
-- 
View this message in context: http://www.nabble.com/How-can-I-tell-Struts-2-to-throw-log-exceptions-for-invalid-OGNL-Expressions-tp11659700p16659934.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: How can I tell Struts 2 to throw/log exceptions for invalid OGNL Expressions

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Jeromy Evans wrote:
> mraible wrote:
>
>>
>> I tried FreeMarker this morning and discovered that the problem 
>> exists there
>> too. Grrr. I've experienced Struts 2 being eliminated as a web framework
>> candidate on a couple projects because of this. Kindof annoying.
>>   
>
> So what do you really want?  My guess here is that you invoked a 
> struts tag and the tag swallowed the error and provided a default to 
> the freemarker template.
>
>

On further thought I think this comes down to an interesting issue with 
coupling between the view and the model.
In struts2 the model is a ValueStack that consists of both a stack and 
map (context).  OGNL is used to address properties or methods in that 
model and it's a trivial for OGNL to log when it fails to match a 
property or method.

In the view, Struts2 provides tags for jsp, ftl or velocity that 
evaluate OGNL expressions to access the model.  More often that not the 
tags fail silently if the expression was invalid or failed to evaluate 
anything.  Herein lies the problem. 

If I were using FTL directly to access the value stack, as a developer I 
could decide how to handle missing properties, blank properties or 
default values with FTL's excellent error handling.  However, when I use 
FTL to invoke a Struts2 tag I lose that benefit as the tag 
implementations *transfer* properties into the FTL context. I think its 
a flaw that Struts2 tags evaluate OGNL expressions themselves prior to 
rendering the template.. 

A tag overhaul is well overdue (but major effort).  I've expressed other 
concerns about the Struts2 tags (XWork Component and UIBean) on several 
occasions already.



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


Re: How can I tell Struts 2 to throw/log exceptions for invalid OGNL Expressions

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
mraible wrote:
> Following up months later as this has come up again now that 2.1 is close to
> release. The current version does log messages for invalid properties, but
> it doesn't blow up for invalid properties which is more of what I'm looking
> for.
>
>   
Hi Matt,
I'm not convinced that you really want what you say you want.

Sure, if you use:
<s:property name="prop"/>
You want to see a message in the log stating that the property didn't 
exist.  Fair enough.

However, if you use:
<s:property name="prop" default="a"/>
Then I presume you don't want a message in the log if property didn't 
exist.  But OGNL doesn't know about the default attribute.

Similarly in FTL if you used:
${parameters.nameValue}?default("a")
You wouldn't want a warning from the framework if nameValue doesn't 
exist because freemarker will handle that if you don't provide a default.

Quite clearly, when setting a property it's the framework's 
responsibility to report if the property didn't exist.
But whose responsibility is it to report that an attempt to read a 
property was made but the property didn't exist. I'm sure many 
algorithms depending on silent failure so they can provide a default.  
My opinion is that it's best handled in the view and FTL has the best 
implementation of this (particularly in 2.4.x where there's improved 
handling for nulls and blanks). 

> When I blogged about this[1], one of the responses was the following:
>
>
>
>   
>> When you are using freemarker as your result technology in struts2 you get
>> great feedback on problems like this. This is not indicative of the whole
>> framework -- just the result-type that you are using (probably jsp?)
>>
>>     
>
> I tried FreeMarker this morning and discovered that the problem exists there
> too. Grrr. I've experienced Struts 2 being eliminated as a web framework
> candidate on a couple projects because of this. Kindof annoying. 
>
>   

So what do you really want?  My guess here is that you invoked a struts 
tag and the tag swallowed the error and provided a default to the 
freemarker template.


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