You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thomas Lulé <th...@lule.fr> on 2010/05/10 09:31:54 UTC
Struts 2 : redirect to action method on type conversion fail ?
Hi,
I've got a form with <s:textfield> mapped with "Long" variables in my
action class.
Also, my jsp displays some pre-computed information (that I retrieve
from database in my action's method).
When the user types letters in the number field, the type conversion
fails, and the JSP is reloaded. But the pre-computed infos are no more
displayed (because we did not execute the action's method).
I didn't find a way to redirect to the action's method even if type
conversion fails.
So I tried to store the pre-computed infos in http parameters by
adding a hidden field :
<s:hidden name="archiveProfile.name" />
<s:property value="archiveProfile.name"/>
it did not work because of the "archiveProfile" thing.
I currently use a workaround, a <s:hidden name="display"/> field that
forces struts 2 to execute the setter :
public void setDisplay(String display){
display();
}
(display() is my method which loads stuff from db.)
That works but i'm afraid of potential side-effects, do you have a better idea ?
Thanks,
Thomas
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 : redirect to action method on type conversion fail ?
Posted by Thomas Lulé <th...@lule.fr>.
Nevermind, my stacktrace came from that issue :
https://issues.apache.org/jira/browse/WW-2850
2010/5/10 Thomas Lulé <th...@lule.fr>:
> One last thing :
>
> Even if everything works, I still get a stacktrace when I submit the
> form to save my object.
>
> I think that the params interceptor tries to set the properties of the
> object "jspProfile" I have in my form (with <s:checkbox
> name="jspProfile.recpCheckErrorCount"/> for example), before the
> prepare interceptor initialize that object.
>
> Even if I initialize the object in the action's constructor, I get the stack.
>
> 2010-05-10 12:34:12,062 [http-8080-Processor24] WARN
> com.opensymphony.xwork2.ognl.OgnlValueStack - Error setting value
> ognl.OgnlException: target is null for setProperty(null,
> "recpCheckErrorCount", [Ljava.lang.String;@62812d)
> at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1651)
> at ognl.ASTProperty.setValueBody(ASTProperty.java:101)
> at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
> at ognl.SimpleNode.setValue(SimpleNode.java:246)
> at ognl.ASTChain.setValueBody(ASTChain.java:172)
> at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
> at ognl.SimpleNode.setValue(SimpleNode.java:246)
> at ognl.Ognl.setValue(Ognl.java:476)
> at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:192)
> at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:155)
> at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:143)
> at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:273)
> at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:187)
> at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
> ...
>
> 2010/5/10 Thomas Lulé <th...@lule.fr>:
>> It works.
>>
>> Thanks a lot Lukasz and Alex.
>>
>> 2010/5/10 Alex Rodriguez Lopez <al...@flordeutopia.pt>:
>>> Hi Thomas,
>>>
>>> use the paramsPrepareParams interceptor stack (or change yours), from
>>> struts-default.xml:
>>>
>>> <!-- An example of the paramsPrepareParams trick. This stack
>>> is exactly the same as the defaultStack, except that it
>>> includes one extra interceptor before the prepare
>>> interceptor:
>>> the params interceptor.
>>>
>>> This is useful for when you wish to apply parameters
>>> directly
>>> to an object that you wish to load externally (such as a DAO
>>> or database or service layer), but can't load that object
>>> until at least the ID parameter has been loaded. By loading
>>> the parameters twice, you can retrieve the object in the
>>> prepare() method, allowing the second params interceptor to
>>> apply the values on the object. -->
>>> <interceptor-stack name="paramsPrepareParamsStack">
>>> ...
>>>
>>> I think this accomplishes what you are looking for (of course you need
>>> setters for the parameters that you want params interceptor to have ready
>>> for you by the time the prepare() method is called).
>>>
>>> Em 10-05-2010 09:39, Thomas Lulé escreveu:
>>>>
>>>> That interceptor looks great, but is there any way to access request
>>>> parameters in the prepare() method ?
>>>>
>>>> The http request provides an "archiveProfileId" parameter and I use
>>>> that parameter to load my object "archiveProfile".
>>>>
>>>> 2010/5/10 Lukasz Lenart<lu...@googlemail.com>:
>>>>>
>>>>> Use Preparable interface instead
>>>>>
>>>>> http://struts.apache.org/2.x/struts2-core/apidocs/com/opensymphony/xwork2/Preparable.html
>>>>>
>>>>>
>>>>> Regards
>>>>> --
>>>>> Łukasz
>>>>> http://www.lenart.org.pl/
>>>>> Kapituła Javarsovia 2010
>>>>> http://javarsovia.pl
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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 2 : redirect to action method on type conversion fail ?
Posted by Thomas Lulé <th...@lule.fr>.
One last thing :
Even if everything works, I still get a stacktrace when I submit the
form to save my object.
I think that the params interceptor tries to set the properties of the
object "jspProfile" I have in my form (with <s:checkbox
name="jspProfile.recpCheckErrorCount"/> for example), before the
prepare interceptor initialize that object.
Even if I initialize the object in the action's constructor, I get the stack.
2010-05-10 12:34:12,062 [http-8080-Processor24] WARN
com.opensymphony.xwork2.ognl.OgnlValueStack - Error setting value
ognl.OgnlException: target is null for setProperty(null,
"recpCheckErrorCount", [Ljava.lang.String;@62812d)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1651)
at ognl.ASTProperty.setValueBody(ASTProperty.java:101)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
at ognl.SimpleNode.setValue(SimpleNode.java:246)
at ognl.ASTChain.setValueBody(ASTChain.java:172)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
at ognl.SimpleNode.setValue(SimpleNode.java:246)
at ognl.Ognl.setValue(Ognl.java:476)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:192)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:155)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:143)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:273)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:187)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
...
2010/5/10 Thomas Lulé <th...@lule.fr>:
> It works.
>
> Thanks a lot Lukasz and Alex.
>
> 2010/5/10 Alex Rodriguez Lopez <al...@flordeutopia.pt>:
>> Hi Thomas,
>>
>> use the paramsPrepareParams interceptor stack (or change yours), from
>> struts-default.xml:
>>
>> <!-- An example of the paramsPrepareParams trick. This stack
>> is exactly the same as the defaultStack, except that it
>> includes one extra interceptor before the prepare
>> interceptor:
>> the params interceptor.
>>
>> This is useful for when you wish to apply parameters
>> directly
>> to an object that you wish to load externally (such as a DAO
>> or database or service layer), but can't load that object
>> until at least the ID parameter has been loaded. By loading
>> the parameters twice, you can retrieve the object in the
>> prepare() method, allowing the second params interceptor to
>> apply the values on the object. -->
>> <interceptor-stack name="paramsPrepareParamsStack">
>> ...
>>
>> I think this accomplishes what you are looking for (of course you need
>> setters for the parameters that you want params interceptor to have ready
>> for you by the time the prepare() method is called).
>>
>> Em 10-05-2010 09:39, Thomas Lulé escreveu:
>>>
>>> That interceptor looks great, but is there any way to access request
>>> parameters in the prepare() method ?
>>>
>>> The http request provides an "archiveProfileId" parameter and I use
>>> that parameter to load my object "archiveProfile".
>>>
>>> 2010/5/10 Lukasz Lenart<lu...@googlemail.com>:
>>>>
>>>> Use Preparable interface instead
>>>>
>>>> http://struts.apache.org/2.x/struts2-core/apidocs/com/opensymphony/xwork2/Preparable.html
>>>>
>>>>
>>>> Regards
>>>> --
>>>> Łukasz
>>>> http://www.lenart.org.pl/
>>>> Kapituła Javarsovia 2010
>>>> http://javarsovia.pl
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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 2 : redirect to action method on type conversion fail ?
Posted by Thomas Lulé <th...@lule.fr>.
It works.
Thanks a lot Lukasz and Alex.
2010/5/10 Alex Rodriguez Lopez <al...@flordeutopia.pt>:
> Hi Thomas,
>
> use the paramsPrepareParams interceptor stack (or change yours), from
> struts-default.xml:
>
> <!-- An example of the paramsPrepareParams trick. This stack
> is exactly the same as the defaultStack, except that it
> includes one extra interceptor before the prepare
> interceptor:
> the params interceptor.
>
> This is useful for when you wish to apply parameters
> directly
> to an object that you wish to load externally (such as a DAO
> or database or service layer), but can't load that object
> until at least the ID parameter has been loaded. By loading
> the parameters twice, you can retrieve the object in the
> prepare() method, allowing the second params interceptor to
> apply the values on the object. -->
> <interceptor-stack name="paramsPrepareParamsStack">
> ...
>
> I think this accomplishes what you are looking for (of course you need
> setters for the parameters that you want params interceptor to have ready
> for you by the time the prepare() method is called).
>
> Em 10-05-2010 09:39, Thomas Lulé escreveu:
>>
>> That interceptor looks great, but is there any way to access request
>> parameters in the prepare() method ?
>>
>> The http request provides an "archiveProfileId" parameter and I use
>> that parameter to load my object "archiveProfile".
>>
>> 2010/5/10 Lukasz Lenart<lu...@googlemail.com>:
>>>
>>> Use Preparable interface instead
>>>
>>> http://struts.apache.org/2.x/struts2-core/apidocs/com/opensymphony/xwork2/Preparable.html
>>>
>>>
>>> Regards
>>> --
>>> Łukasz
>>> http://www.lenart.org.pl/
>>> Kapituła Javarsovia 2010
>>> http://javarsovia.pl
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
>
> ---------------------------------------------------------------------
> 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 2 : redirect to action method on type conversion fail
?
Posted by Alex Rodriguez Lopez <al...@flordeutopia.pt>.
Hi Thomas,
use the paramsPrepareParams interceptor stack (or change yours), from
struts-default.xml:
<!-- An example of the paramsPrepareParams trick. This stack
is exactly the same as the defaultStack, except that it
includes one extra interceptor before the prepare
interceptor:
the params interceptor.
This is useful for when you wish to apply parameters
directly
to an object that you wish to load externally (such as
a DAO
or database or service layer), but can't load that object
until at least the ID parameter has been loaded. By
loading
the parameters twice, you can retrieve the object in the
prepare() method, allowing the second params
interceptor to
apply the values on the object. -->
<interceptor-stack name="paramsPrepareParamsStack">
...
I think this accomplishes what you are looking for (of course you need
setters for the parameters that you want params interceptor to have
ready for you by the time the prepare() method is called).
Em 10-05-2010 09:39, Thomas Lulé escreveu:
> That interceptor looks great, but is there any way to access request
> parameters in the prepare() method ?
>
> The http request provides an "archiveProfileId" parameter and I use
> that parameter to load my object "archiveProfile".
>
> 2010/5/10 Lukasz Lenart<lu...@googlemail.com>:
>> Use Preparable interface instead
>> http://struts.apache.org/2.x/struts2-core/apidocs/com/opensymphony/xwork2/Preparable.html
>>
>>
>> Regards
>> --
>> Łukasz
>> http://www.lenart.org.pl/
>> Kapituła Javarsovia 2010
>> http://javarsovia.pl
>>
>> ---------------------------------------------------------------------
>> 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 : redirect to action method on type conversion fail ?
Posted by Thomas Lulé <th...@lule.fr>.
That interceptor looks great, but is there any way to access request
parameters in the prepare() method ?
The http request provides an "archiveProfileId" parameter and I use
that parameter to load my object "archiveProfile".
2010/5/10 Lukasz Lenart <lu...@googlemail.com>:
> Use Preparable interface instead
> http://struts.apache.org/2.x/struts2-core/apidocs/com/opensymphony/xwork2/Preparable.html
>
>
> Regards
> --
> Łukasz
> http://www.lenart.org.pl/
> Kapituła Javarsovia 2010
> http://javarsovia.pl
>
> ---------------------------------------------------------------------
> 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 2 : redirect to action method on type conversion fail ?
Posted by Lukasz Lenart <lu...@googlemail.com>.
Use Preparable interface instead
http://struts.apache.org/2.x/struts2-core/apidocs/com/opensymphony/xwork2/Preparable.html
Regards
--
Łukasz
http://www.lenart.org.pl/
Kapituła Javarsovia 2010
http://javarsovia.pl
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org