You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matt Luce <ma...@gmail.com> on 2007/06/09 21:39:24 UTC
Programmatic Validation in Action
Has anyone attempted to use programmatic validation in Struts 2? When I
add an actionError and return INPUT, it properly goes back to the page
with the form, but it does not keep the values that I typed. Shouldn't
that work? This is how it worked in Struts 1.
package com.company.action;
import com.opensymphony.xwork2.ActionSupport;
public class ExampleValidateAction extends ActionSupport
{
private string attribute;
public String execute() throws Exception
{
// complicated validation logic. Too complicated for xml
validation
this.addActionError("Validation Error");
return INPUT;
}
public string getAttribute()
{
return attribute;
}
public void setAttribue(String attr)
{
this.attribute = attr;
}
}
Re: Programmatic Validation in Action
Posted by Caine Lai <ca...@gmail.com>.
I hope this code:
public void setAttribue(String attr)
{
this.attribute = attr;
}
Is a typo? If not, this is why your attribute is not being set in your
action class.
Also, since you are forwarding to the same page regardless of success,
failure and input... are you sure it is actually failing and returning
INPUT?
On 6/9/07, Matt Luce <ma...@gmail.com> wrote:
>
> Has anyone attempted to use programmatic validation in Struts 2? When I
> add an actionError and return INPUT, it properly goes back to the page
> with the form, but it does not keep the values that I typed. Shouldn't
> that work? This is how it worked in Struts 1.
>
>
> package com.company.action;
>
> import com.opensymphony.xwork2.ActionSupport;
>
>
> public class ExampleValidateAction extends ActionSupport
> {
>
> private string attribute;
>
> public String execute() throws Exception
> {
>
> // complicated validation logic. Too complicated for xml
> validation
> this.addActionError("Validation Error");
> return INPUT;
>
>
> }
>
> public string getAttribute()
> {
> return attribute;
> }
>
> public void setAttribue(String attr)
> {
> this.attribute = attr;
> }
>
> }
>
>
Re: Programmatic Validation in Action
Posted by Torsten Römer <to...@luniks.net>.
I put my validation code in the validate() method and use addFieldError().
To avoid validation to be performed on initial form display, I made a
mapping like this:
<action name="reservation_*"
class="net.luniks.bagpowerride.page.Reservation"
method="{1}">
<result name="success" type="tiles">bookedTiles</result>
<result name="input" type="tiles">reservationTiles</result>
<result name="error" type="tiles">errorTiles</result>
</action>
and call the action "reservation_input". Struts knows then that it
should not perform validation.
The form itself then calls the action "reservation".
It works fine for me, just that special characters (üöä...) in the typed
values are sometimes messed up when the form is redisplayed on
validation error :-(
Torsten
Matt Luce schrieb:
> Has anyone attempted to use programmatic validation in Struts 2? When I
> add an actionError and return INPUT, it properly goes back to the page
> with the form, but it does not keep the values that I typed. Shouldn't
> that work? This is how it worked in Struts 1.
>
>
> package com.company.action;
>
> import com.opensymphony.xwork2.ActionSupport;
>
>
> public class ExampleValidateAction extends ActionSupport
> {
>
> private string attribute;
>
> public String execute() throws Exception
> {
>
> // complicated validation logic. Too complicated for xml validation
> this.addActionError("Validation Error");
> return INPUT;
>
>
> }
>
> public string getAttribute()
> {
> return attribute;
> }
>
> public void setAttribue(String attr)
> {
> this.attribute = attr;
> }
>
> }
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Programmatic Validation in Action
Posted by Ma...@wellsfargo.com.
Sure, it's really simple:
<action name="save" class="exampleAction"> // this is action is
configured in spring
<result name="input">/update.jsp</result>
<result>/update.jsp</result>
<result name="error">/update.jsp</result>
</action>
When it goes to the "input" result, the values I typed in are no longer
present.
-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com]
Sent: Saturday, June 09, 2007 2:49 PM
To: Struts Users Mailing List
Subject: Re: Programmatic Validation in Action
--- Matt Luce <ma...@gmail.com> wrote:
> Has anyone attempted to use programmatic validation in Struts 2?
Sure, although I still used the validation interfaces.
What does your mapping look like?
d.
________________________________________________________________________
____________
Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/
---------------------------------------------------------------------
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: Programmatic Validation in Action
Posted by Dave Newton <ne...@yahoo.com>.
--- Matt Luce <ma...@gmail.com> wrote:
> Has anyone attempted to use programmatic validation
> in Struts 2?
Sure, although I still used the validation interfaces.
What does your mapping look like?
d.
____________________________________________________________________________________
Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org