You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tom Bednarz <li...@bednarz.ch> on 2007/02/26 18:47:41 UTC
Strange problem with Validators in Struts 1.2.9
I have the following problem:
My validator gets NOT called as soon as I initialize some properties in
my form. In my form bean I have:
public class QueryTripsForm extends ValidatorActionForm
{
private String startPeriodDisplay = "2007-01-01";
private String endPeriodDisplay = "2099-12-31";
....
// other properties, getters and setters doing
// type conversions from string to date etc...
}
I did NOT implement (overwrite) the validate method, but I implemented
a reset method.
in my struts-config.xml I have:
....
<form-bean name="queryTripsForm"
type="ch.smartsol.struts.form.QueryTripsForm" />
...
<action
name="queryTripsForm"
path="/queryTrips"
scope="request"
input="/form/queryTrips.jsp"
validate="true"
type="ch.smartsol.struts.action.ListTripsAction">
<forward name="Success" path="/form/queryTrips.jsp" />
</action>
...
and in my validation.xml I have
<form name="/queryTrips">
<field property="startPeriodDisplay" depends="required, date">
<msg name="required" key="QueryTripsForm.start.required"/>
<msg name="date" key="QueryTripsForm.start.date"/>
<var>
<var-name>datePatternStrict</var-name>
<var-value>yyyy-MM-dd</var-value>
</var>
</field>
<field property="endPeriodDisplay" depends="required, date">
<msg name="required" key="QueryTripsForm.end.required"/>
<msg name="date" key="QueryTripsForm.end.date"/>
<var>
<var-name>datePatternStrict</var-name>
<var-value>yyyy-MM-dd</var-value>
</var>
</field>
</form>
If I do NOT initialize the two strings in my form bean the validator is
called and the first time the form displays it contains the validation
error messages!! If I initialize the two strings with a default value
(as shown above), the validator is NOT called at all and the user can
submit empty fields.
Any idea what I am doing wrong here???
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Strange problem with Validators in Struts 1.2.9
Posted by Dave Newton <ne...@yahoo.com>.
--- Tom Bednarz <li...@bednarz.ch> wrote:
> I still do not feel very comfortable with writing
> that many actions around 'CRUDing' an object.
I generally use a single action for CRUD. You may want
to look at DispatchAction (or something like that,
it's been awhile) and consider the GET/POST division
of labor I mentioned.
d.
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Strange problem with Validators in Struts 1.2.9
Posted by Tom Bednarz <li...@bednarz.ch>.
Yeah, looks like it is the wrong action I am calling, or better I need
more actions to process a single user input. I still do not feel very
comfortable with writing that many actions around 'CRUDing' an object.
Thanks a lot anyway!
Tom
Dave Newton wrote:
> --- Tom Bednarz <li...@bednarz.ch> wrote:
>> Any idea what I am doing wrong here???
>
> Not "wrong", really, but probably you're using an
> action-mapping with validate='true' to do the initial
> form display. With no defaults it will validate with
> an error.
>
> Two ways to get around this are:
>
> 1) Use a preliminary action to show the page with no
> auto-validation and submit to the action with the
> validation turned on.
>
> 2) Submit w/ a POST and inside the action check for
> GET vs POST and call validate manually (this is what I
> did and had base classes to encapsulate that
> functionality).
>
> There are probably several more good (or better!)
> solutions.
>
> d.
>
>
>
>
> ____________________________________________________________________________________
> Never miss an email again!
> Yahoo! Toolbar alerts you the instant new Mail arrives.
> http://tools.search.yahoo.com/toolbar/features/mail/
>
> ---------------------------------------------------------------------
> 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: Strange problem with Validators in Struts 1.2.9
Posted by Dave Newton <ne...@yahoo.com>.
--- Tom Bednarz <li...@bednarz.ch> wrote:
> Any idea what I am doing wrong here???
Not "wrong", really, but probably you're using an
action-mapping with validate='true' to do the initial
form display. With no defaults it will validate with
an error.
Two ways to get around this are:
1) Use a preliminary action to show the page with no
auto-validation and submit to the action with the
validation turned on.
2) Submit w/ a POST and inside the action check for
GET vs POST and call validate manually (this is what I
did and had base classes to encapsulate that
functionality).
There are probably several more good (or better!)
solutions.
d.
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org