struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicole Luneburg <Nicole.Luneb...@lisasoft.com>
Subject RE: struts2 validation
Date Tue, 15 Jul 2008 00:10:22 GMT
Ah!
Now I understand ... Looks like I will be changing a few things in this project ...
Thanks for your help!

-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com]
Sent: Monday, 14 July 2008 10:22 PM
To: Struts Users Mailing List
Subject: RE: struts2 validation

If you don't have an action property named "fieldname" then not only will validation not work
but neither will normal property copying (from form to action).

If, for example, you have a MyForm named "form", and has an appropriate getter/setter, its
form element would look like this:

<s:textfield name="form.fieldName"/>

If you're handling validation programmatically (via the Validateable interface and the action's
validate() method) you'd then validate against the MyForm instance, for example:

public void validate() {
    if (StringUtils.isBlank(this.form.getFieldName())) {
        ...
    }
    ...
}

It sort of seems like you're implementing a bit of ModelDriven, but manually--not a problem,
but seems a bit duplicative.

Dave

--- On Mon, 7/14/08, Nicole Luneburg wrote:

> From: Nicole Luneburg <Nicole.Luneburg@lisasoft.com>
> Subject: RE: struts2 validation
> To: "Struts Users Mailing List" <user@struts.apache.org>
> Date: Monday, July 14, 2008, 3:16 AM
> ps. My post added some "3D" text that isn't
> supposed to be there ...
>
> Thanks Jeromy.
>
> Yes I do have a <s:head> attribute, maybe not
> *exactly* but I have:
> <s:head theme="ajax" />
>
> Apologies for the confusion.
> What I meant in my pevious post was that I had tried a few
> ways to do this validation task.
> In my initial post I had described one of these attempts
> which I think should have worked.
>
> What I am getting regardless of what sort of validation I
> try to implement is this error:
>
> java.lang.StringIndexOutOfBoundsException: String index out
> of range: -7
>
> You mentioned the getters and setters for the fieldnames
> ... this only works though if the fields are stored in the
> action right?
> coz the fields I have aren't stored in the action, they
> are stored in a Form class.
>
> Ie my action looks something like:
>
> public String execute() {
>         MyForm myForm = (MyForm)super.form;
>         String myField = myForm.getFieldName();
> }
>
> Markus: Thanks for your reply too, I am trying it right
> now. Just want this to work grrr
>
>
> -----Original Message-----
> From: Jeromy Evans
> [mailto:jeromy.evans@blueskyminds.com.au]
> Sent: Monday, 14 July 2008 4:25 PM
> To: Struts Users Mailing List
> Subject: Re: struts2 validation
>
> Nicole Luneburg wrote:
> >
> >
> >
> > <s:form action=3D"myaction"
> method=3D"post" validate=3D"true">
> >
> The validate attribute here is used to enable client-side
> validation
> only.  That will only work if you include the
> <s:head> attribute in the
> page.
>
>
> >
> >
> > My setup is that I have an Action class, which uses a
> Form to set and get f= ield values from the JSP page.
> >
> > In Struts1 I was using the validate(...) method in the
> Form class.
> >
> > It seems none of the Struts2 validation examples on
> the net are working for=  me.
> >
> >
>
> You haven't mentioned whether you're using XML
> validation or
> annotation-based validation.  If by not working you mean
> "does nothing",
> then your XML file is probably incorrectly named or your
> missing an
> annotation.  (You need to enable this separately from
> client-side
> validation)
>
> Whatever the case, the main difference between Struts1 and
> Struts2 here
> is that Struts2 performs validation on the Object, not on
> the form
> parameters.
> That means, to check that "fieldName" is
> non-blank, it will call
> getFieldName() after setFieldName() was called by the
> ParametersInterceptor.
>
> A common problem is to forget the getter, but in that case
> Struts will
> keep returning INPUT (validation failed) instead of
> invoking your action.
>
> Hope that helps,
> Jeromy Evans
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
>
>
> The contents of this email are confidential and may be
> subject to legal or professional privilege and copyright.
> No representation is made that this email is free of
> viruses or other defects. If you have received this
> communication in error, you may not copy or distribute any
> part of it or otherwise disclose its contents to anyone.
> Please advise the sender of your incorrect receipt of this
> correspondence.
>
> ---------------------------------------------------------------------
> 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


The contents of this email are confidential and may be subject to legal or professional privilege
and copyright. No representation is made that this email is free of viruses or other defects.
If you have received this communication in error, you may not copy or distribute any part
of it or otherwise disclose its contents to anyone. Please advise the sender of your incorrect
receipt of this correspondence.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message