struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Römer <torsten.roe...@luniks.net>
Subject Re: Programmatic Validation in Action
Date Sat, 09 Jun 2007 22:14:18 GMT
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


Mime
View raw message