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 2007/07/18 01:26:30 UTC

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

I have the following class:

public class TestAction {

    public static String concat(String str1, String str2) {
        return str1 + " and " + str2;
    }
}

In a JSP, I can write the following and it works fine:

<s:property value="@org.appfuse.web.TestAction@concat('1', '2')"/>

However, if I change it to an invalid class name, it fails silently:

<s:property value="@org.appfuse.web.InvalidClass@concat('1', '2')"/>

I've tried turning up the logging for org.apache.struts2,
com.opensymphony.xwork2 and ognl - but it still fails silently. Any ideas
how to get better error messages about invalid OGNL expressions?

Thanks,

Matt
-- 
View this message in context: http://www.nabble.com/How-can-I-tell-Struts-2-to-throw-log-exceptions-for-invalid-OGNL-Expressions-tf4100102.html#a11659700
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 Ted Husted <hu...@apache.org>.
Moving to dev@ ....

It occurred to me that if we make this kind of change, we might want
to take the behavior of the text tag/message resources into
consideration too. Right now, if a message resource is not found, the
tag displays the name of the tag, e.g.

<s:text name="doesntexist" />

renders

doesntexist

Other tags might do the same thing (print the property name) if the
property doesn't exist. Or, alternatively, when in devmode we could
log when a message resource is not found. (Right now, that doesn't
happen.) I'm just thinking there should be consistency between the
literal-text and message-resource behaviors.

-Ted.


On 9/6/07, Ted Husted <hu...@apache.org> 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: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-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


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

Posted by mraible <ma...@raibledesigns.com>.
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 Ted Husted <hu...@apache.org>.
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


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

Posted by mraible <ma...@raibledesigns.com>.
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


Ted Husted wrote:
> 
> Have you tried doing this with devMode turned on?
> 
> <struts>
>     <constant name="struts.devMode" value="true" />
> 
> For example, if I add to the form on MailReader Login.jsp
> 
>      <s:textfield name="doesntexist" />
> 
> and submit the form with devmode=true, the following is logged
> 
> Sep 6, 2007 11:14:52 AM
> com.opensymphony.xwork2.validator.ActionValidatorManagerFactory
> <clinit>
> INFO: Detected AnnotationActionValidatorManager, initializing it...
> Sep 6, 2007 11:15:01 AM
> com.opensymphony.xwork2.interceptor.ParametersInterceptor
> setParameters
> SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception
> caught setting 'button.save' on 'class mailreader2.Login: Error
> setting expression 'button.save' with value
> '[Ljava.lang.String;@e33e18'
> Sep 6, 2007 11:15:01 AM
> com.opensymphony.xwork2.interceptor.ParametersInterceptor
> setParameters
> SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception
> caught setting 'doesntexist' on 'class mailreader2.Login: Error
> setting expression 'doesntexist' with value
> '[Ljava.lang.String;@15f1f9c'
> 
> HTH, Ted.
> http://husted.com/ted/blog/
> 
> 
> On 8/28/07, mraible <ma...@raibledesigns.com> wrote:
>>
>> I'm now digging into XWork to see if I can add this functionality. I have
>> the
>> following in a JSP and I'd like to receive an error from it:
>>
>> <s:property value="methodDoesntExist('foo')"/>
>>
>> OgnlValueStack lines 260-265:
>>
>>             Object value = OgnlUtil.getValue(expr, context, root,
>> asType);
>>             if (value != null) {
>>                 return value;
>>             } else {
>>                 return findInContext(expr);
>>             }
>>
>> In this example, the following method is called with
>> "methodDoesntExist('foo')"" as the value for name:
>>
>>     private Object findInContext(String name) {
>>         return getContext().get(name);
>>     }
>>
>> So if nothing is found in the map, null is returned (I'm assuming). It
>> seems
>> like the if/else statement might be better with the following:
>>
>>             Object value = OgnlUtil.getValue(expr, context, root,
>> asType);
>>             if (value != null) {
>>                 return value;
>>             } else {
>>                 value = findInContext(expr);
>>                 if (value == null) {
>>                     logLookupFailure(expr, ??);
>>                 }
>>             }
>>
>> However, I don't know what to put in the ?? location. Thoughts on this?
>>
>> Thanks,
>>
>> Matt
>>
>> mraible wrote:
>> >
>> > Is it possible to use altSyntax to solve this problem? In other words,
>> > require %{} around all expressions? Looking through the docs, it
>> doesn't
>> > seem like altSyntax is supported in Struts 2.
>> >
>> > https://issues.apache.org/struts/browse/WW-1819
>> >
>> > Thanks,
>> >
>> > Matt
>> >
>> >
>> > mraible wrote:
>> >>
>> >>
>> >> mraible wrote:
>> >>>
>> >>> I have the following class:
>> >>>
>> >>> public class TestAction {
>> >>>
>> >>>     public static String concat(String str1, String str2) {
>> >>>         return str1 + " and " + str2;
>> >>>     }
>> >>> }
>> >>>
>> >>> In a JSP, I can write the following and it works fine:
>> >>>
>> >>> <s:property value="@org.appfuse.web.TestAction@concat('1', '2')"/>
>> >>>
>> >>> However, if I change it to an invalid class name, it fails silently:
>> >>>
>> >>> <s:property value="@org.appfuse.web.InvalidClass@concat('1', '2')"/>
>> >>>
>> >>> I've tried turning up the logging for org.apache.struts2,
>> >>> com.opensymphony.xwork2 and ognl - but it still fails silently. Any
>> >>> ideas how to get better error messages about invalid OGNL
>> expressions?
>> >>>
>> >>
>> >> I'll take that as a "no", it is not possible to get better error
>> >> messages. That's too bad since it seems I get better type-safety and
>> >> errors from scriptlets instead of OGNL.
>> >>
>> >> <%@ page
>> >>
>> import="org.foo.bar.baz.SettingsServlet,org.foo.bar.baz.enums.EnumCodec"
>> >> %>
>> >>
>> >> <c:set
>> >>
>> var="q"><%=EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates)%></c:set>
>> >>
>> >> <s:property value="url(@vs@SETTINGS_SERVLET).q('${q}')"/>
>> >>
>> >> VS:
>> >>
>> >> <s:property
>> >>
>> value="url(@vs@SETTINGS_SERVLET).q(@org.foo.bar.baz.enums.EnumCodec@URL.encode(@org.foo.bar.baz.SettingsServlet$ACTIONS@networkUpdates))"/>
>> >>
>> >> The framework I'm looking to migrate to Struts 2 has the ability for
>> it's
>> >> EL to read from imported Statics - a pretty cool feature IMO.
>> >>
>> >>
>> ${url(pageBean.MAPPING.SETTINGS_SERVLET).q(EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates))}
>> >>
>> >> Matt
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-can-I-tell-Struts-2-to-throw-log-exceptions-for-invalid-OGNL-Expressions-tf4100102.html#a12373437
>> 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
>>
>>
> 
> 
> -- 
> HTH, Ted <http://www.husted.com/ted/blog/>
> 
> ---------------------------------------------------------------------
> 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-tf4100102.html#a12525268
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 Ted Husted <hu...@apache.org>.
Have you tried doing this with devMode turned on?

<struts>
    <constant name="struts.devMode" value="true" />

For example, if I add to the form on MailReader Login.jsp

     <s:textfield name="doesntexist" />

and submit the form with devmode=true, the following is logged

Sep 6, 2007 11:14:52 AM
com.opensymphony.xwork2.validator.ActionValidatorManagerFactory
<clinit>
INFO: Detected AnnotationActionValidatorManager, initializing it...
Sep 6, 2007 11:15:01 AM
com.opensymphony.xwork2.interceptor.ParametersInterceptor
setParameters
SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception
caught setting 'button.save' on 'class mailreader2.Login: Error
setting expression 'button.save' with value
'[Ljava.lang.String;@e33e18'
Sep 6, 2007 11:15:01 AM
com.opensymphony.xwork2.interceptor.ParametersInterceptor
setParameters
SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception
caught setting 'doesntexist' on 'class mailreader2.Login: Error
setting expression 'doesntexist' with value
'[Ljava.lang.String;@15f1f9c'

HTH, Ted.
http://husted.com/ted/blog/


On 8/28/07, mraible <ma...@raibledesigns.com> wrote:
>
> I'm now digging into XWork to see if I can add this functionality. I have the
> following in a JSP and I'd like to receive an error from it:
>
> <s:property value="methodDoesntExist('foo')"/>
>
> OgnlValueStack lines 260-265:
>
>             Object value = OgnlUtil.getValue(expr, context, root, asType);
>             if (value != null) {
>                 return value;
>             } else {
>                 return findInContext(expr);
>             }
>
> In this example, the following method is called with
> "methodDoesntExist('foo')"" as the value for name:
>
>     private Object findInContext(String name) {
>         return getContext().get(name);
>     }
>
> So if nothing is found in the map, null is returned (I'm assuming). It seems
> like the if/else statement might be better with the following:
>
>             Object value = OgnlUtil.getValue(expr, context, root, asType);
>             if (value != null) {
>                 return value;
>             } else {
>                 value = findInContext(expr);
>                 if (value == null) {
>                     logLookupFailure(expr, ??);
>                 }
>             }
>
> However, I don't know what to put in the ?? location. Thoughts on this?
>
> Thanks,
>
> Matt
>
> mraible wrote:
> >
> > Is it possible to use altSyntax to solve this problem? In other words,
> > require %{} around all expressions? Looking through the docs, it doesn't
> > seem like altSyntax is supported in Struts 2.
> >
> > https://issues.apache.org/struts/browse/WW-1819
> >
> > Thanks,
> >
> > Matt
> >
> >
> > mraible wrote:
> >>
> >>
> >> mraible wrote:
> >>>
> >>> I have the following class:
> >>>
> >>> public class TestAction {
> >>>
> >>>     public static String concat(String str1, String str2) {
> >>>         return str1 + " and " + str2;
> >>>     }
> >>> }
> >>>
> >>> In a JSP, I can write the following and it works fine:
> >>>
> >>> <s:property value="@org.appfuse.web.TestAction@concat('1', '2')"/>
> >>>
> >>> However, if I change it to an invalid class name, it fails silently:
> >>>
> >>> <s:property value="@org.appfuse.web.InvalidClass@concat('1', '2')"/>
> >>>
> >>> I've tried turning up the logging for org.apache.struts2,
> >>> com.opensymphony.xwork2 and ognl - but it still fails silently. Any
> >>> ideas how to get better error messages about invalid OGNL expressions?
> >>>
> >>
> >> I'll take that as a "no", it is not possible to get better error
> >> messages. That's too bad since it seems I get better type-safety and
> >> errors from scriptlets instead of OGNL.
> >>
> >> <%@ page
> >> import="org.foo.bar.baz.SettingsServlet,org.foo.bar.baz.enums.EnumCodec"
> >> %>
> >>
> >> <c:set
> >> var="q"><%=EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates)%></c:set>
> >>
> >> <s:property value="url(@vs@SETTINGS_SERVLET).q('${q}')"/>
> >>
> >> VS:
> >>
> >> <s:property
> >> value="url(@vs@SETTINGS_SERVLET).q(@org.foo.bar.baz.enums.EnumCodec@URL.encode(@org.foo.bar.baz.SettingsServlet$ACTIONS@networkUpdates))"/>
> >>
> >> The framework I'm looking to migrate to Struts 2 has the ability for it's
> >> EL to read from imported Statics - a pretty cool feature IMO.
> >>
> >> ${url(pageBean.MAPPING.SETTINGS_SERVLET).q(EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates))}
> >>
> >> Matt
> >>
> >>
> >
> >
>
> --
> View this message in context: http://www.nabble.com/How-can-I-tell-Struts-2-to-throw-log-exceptions-for-invalid-OGNL-Expressions-tf4100102.html#a12373437
> 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
>
>


-- 
HTH, Ted <http://www.husted.com/ted/blog/>

---------------------------------------------------------------------
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>.
I'm now digging into XWork to see if I can add this functionality. I have the
following in a JSP and I'd like to receive an error from it:

<s:property value="methodDoesntExist('foo')"/>

OgnlValueStack lines 260-265:

            Object value = OgnlUtil.getValue(expr, context, root, asType);
            if (value != null) {
                return value;
            } else {
                return findInContext(expr);
            }

In this example, the following method is called with
"methodDoesntExist('foo')"" as the value for name:

    private Object findInContext(String name) {
        return getContext().get(name);
    }

So if nothing is found in the map, null is returned (I'm assuming). It seems
like the if/else statement might be better with the following:

            Object value = OgnlUtil.getValue(expr, context, root, asType);
            if (value != null) {
                return value;
            } else {
                value = findInContext(expr);
                if (value == null) {
                    logLookupFailure(expr, ??);
                }
            }

However, I don't know what to put in the ?? location. Thoughts on this?

Thanks,

Matt

mraible wrote:
> 
> Is it possible to use altSyntax to solve this problem? In other words,
> require %{} around all expressions? Looking through the docs, it doesn't
> seem like altSyntax is supported in Struts 2.
> 
> https://issues.apache.org/struts/browse/WW-1819
> 
> Thanks,
> 
> Matt
> 
> 
> mraible wrote:
>> 
>> 
>> mraible wrote:
>>> 
>>> I have the following class:
>>> 
>>> public class TestAction {
>>> 
>>>     public static String concat(String str1, String str2) {
>>>         return str1 + " and " + str2;
>>>     }
>>> }
>>> 
>>> In a JSP, I can write the following and it works fine:
>>> 
>>> <s:property value="@org.appfuse.web.TestAction@concat('1', '2')"/>
>>> 
>>> However, if I change it to an invalid class name, it fails silently:
>>> 
>>> <s:property value="@org.appfuse.web.InvalidClass@concat('1', '2')"/>
>>> 
>>> I've tried turning up the logging for org.apache.struts2,
>>> com.opensymphony.xwork2 and ognl - but it still fails silently. Any
>>> ideas how to get better error messages about invalid OGNL expressions?
>>> 
>> 
>> I'll take that as a "no", it is not possible to get better error
>> messages. That's too bad since it seems I get better type-safety and
>> errors from scriptlets instead of OGNL.
>> 
>> <%@ page
>> import="org.foo.bar.baz.SettingsServlet,org.foo.bar.baz.enums.EnumCodec" 
>> %>
>> 
>> <c:set
>> var="q"><%=EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates)%></c:set>
>> 
>> <s:property value="url(@vs@SETTINGS_SERVLET).q('${q}')"/>
>> 
>> VS:
>> 
>> <s:property
>> value="url(@vs@SETTINGS_SERVLET).q(@org.foo.bar.baz.enums.EnumCodec@URL.encode(@org.foo.bar.baz.SettingsServlet$ACTIONS@networkUpdates))"/>
>> 
>> The framework I'm looking to migrate to Struts 2 has the ability for it's
>> EL to read from imported Statics - a pretty cool feature IMO.
>> 
>> ${url(pageBean.MAPPING.SETTINGS_SERVLET).q(EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates))}
>> 
>> Matt
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-tell-Struts-2-to-throw-log-exceptions-for-invalid-OGNL-Expressions-tf4100102.html#a12373437
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 mraible <ma...@raibledesigns.com>.
Is it possible to use altSyntax to solve this problem? In other words,
require %{} around all expressions? Looking through the docs, it doesn't
seem like altSyntax is supported in Struts 2.

https://issues.apache.org/struts/browse/WW-1819

Thanks,

Matt


mraible wrote:
> 
> 
> mraible wrote:
>> 
>> I have the following class:
>> 
>> public class TestAction {
>> 
>>     public static String concat(String str1, String str2) {
>>         return str1 + " and " + str2;
>>     }
>> }
>> 
>> In a JSP, I can write the following and it works fine:
>> 
>> <s:property value="@org.appfuse.web.TestAction@concat('1', '2')"/>
>> 
>> However, if I change it to an invalid class name, it fails silently:
>> 
>> <s:property value="@org.appfuse.web.InvalidClass@concat('1', '2')"/>
>> 
>> I've tried turning up the logging for org.apache.struts2,
>> com.opensymphony.xwork2 and ognl - but it still fails silently. Any ideas
>> how to get better error messages about invalid OGNL expressions?
>> 
> 
> I'll take that as a "no", it is not possible to get better error messages.
> That's too bad since it seems I get better type-safety and errors from
> scriptlets instead of OGNL.
> 
> <%@ page
> import="org.foo.bar.baz.SettingsServlet,org.foo.bar.baz.enums.EnumCodec" 
> %>
> 
> <c:set
> var="q"><%=EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates)%></c:set>
> 
> <s:property value="url(@vs@SETTINGS_SERVLET).q('${q}')"/>
> 
> VS:
> 
> <s:property
> value="url(@vs@SETTINGS_SERVLET).q(@org.foo.bar.baz.enums.EnumCodec@URL.encode(@org.foo.bar.baz.SettingsServlet$ACTIONS@networkUpdates))"/>
> 
> The framework I'm looking to migrate to Struts 2 has the ability for it's
> EL to read from imported Statics - a pretty cool feature IMO.
> 
> ${url(pageBean.MAPPING.SETTINGS_SERVLET).q(EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates))}
> 
> Matt
> 
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-tell-Struts-2-to-throw-log-exceptions-for-invalid-OGNL-Expressions-tf4100102.html#a12351943
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 mraible <ma...@raibledesigns.com>.

mraible wrote:
> 
> I have the following class:
> 
> public class TestAction {
> 
>     public static String concat(String str1, String str2) {
>         return str1 + " and " + str2;
>     }
> }
> 
> In a JSP, I can write the following and it works fine:
> 
> <s:property value="@org.appfuse.web.TestAction@concat('1', '2')"/>
> 
> However, if I change it to an invalid class name, it fails silently:
> 
> <s:property value="@org.appfuse.web.InvalidClass@concat('1', '2')"/>
> 
> I've tried turning up the logging for org.apache.struts2,
> com.opensymphony.xwork2 and ognl - but it still fails silently. Any ideas
> how to get better error messages about invalid OGNL expressions?
> 

I'll take that as a "no", it is not possible to get better error messages.
That's too bad since it seems I get better type-safety and errors from
scriptlets instead of OGNL.

<%@ page
import="org.foo.bar.baz.SettingsServlet,org.foo.bar.baz.enums.EnumCodec"  %>

<c:set
var="q"><%=EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates)%></c:set>

<s:property value="url(@vs@SETTINGS_SERVLET).q('${q}')"/>

VS:

<s:property
value="url(@vs@SETTINGS_SERVLET).q(@org.foo.bar.baz.enums.EnumCodec@URL.encode(@org.foo.bar.baz.SettingsServlet$ACTIONS@networkUpdates))"/>

The framework I'm looking to migrate to Struts 2 has the ability for it's EL
to read from imported Statics - a pretty cool feature IMO.

${url(pageBean.MAPPING.SETTINGS_SERVLET).q(EnumCodec.URL.encode(SettingsServlet.ACTIONS.networkUpdates))}

Matt

-- 
View this message in context: http://www.nabble.com/How-can-I-tell-Struts-2-to-throw-log-exceptions-for-invalid-OGNL-Expressions-tf4100102.html#a12282397
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