You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Greg Akins <an...@gmail.com> on 2010/12/09 19:46:10 UTC

Cancel in a form re: bypass Validation

I need to have a "Cancel" button on a form that skips the validation
(Struts 2.2.1).  This seems harder than it should be and maybe I'm
missing something.

I've read a few posts about this and ended using the validation
interceptorref to get this to work.

I've had problems getting the interceptorref mechanism to work

@Action(value = "hello-world-cancel",
			interceptorRefs = { @InterceptorRef(value = "validation", params = {
					"excludeMethods", "cancel" })},
					results = { @Result(name = SUCCESS, location="/jsp/logon.jsp") })
	public String cancel() throws Exception {
		LOG.debug("Cancelled", "The form has been cancelled");
		return SUCCESS;
	}

The problem is.. I've got this working as part of the Maven
struts-archetype-starter application.  However, I can't manage to get
the same thing working on my application

Bother are using theme="xhtml".. but my application will only do the
Error Messages and labels if the validate="true" is set on the form.
However, setting the validate=true on the form forces client-side
javascript to be built which is run everytime the form is submitted,
even if it's submitted from the cancel button.

The HelloWorld application looks like it's using serverside validation
(since there isn't any javascript in the page.. but the error messages
and labels still appear).

Any thoughts on what I might be missing?
-- 
Greg Akins

http://insomnia-consulting.org
http://www.pghcodingdojo.org
http://pittjug.dev.java.net
http://twitter.com/akinsgre
http://www.linkedin.com/in/akinsgre

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


Re: Cancel in a form re: bypass Validation

Posted by Dave Newton <da...@gmail.com>.
On Fri, Dec 10, 2010 at 8:19 AM, Greg Akins <an...@gmail.com> wrote:

> Thanks Li.. you're correct.   And I'm still wondering why the form in
> my Application won't display fieldError messages when I use only
> Serverside validation.
>
> If, on the s:form, I use validation="true" the javascript is included
> to do validation, and the errorMessages automagically appear
> (theme="xhtml")
>
> However, if I don't use <s:form validation="true">  the validation
> still works (page result is INPUT) but the error messages aren't
> rendered.  When I create a simple "Hello World" app, it does work; and
> I can't figure out which bit of Struts I've broken in trying to get my
> application's validation to work.
>

Did you already post the code/config? Try posting it again; I never saw it.

<s:form>'s "validation" attribute has nothing to do with server-side
validation, that's only an indication of client-side validation. So it's
likely something else is wrong.

Dave

Re: Cancel in a form re: bypass Validation

Posted by Greg Akins <an...@gmail.com>.
Thanks Li.. you're correct.   And I'm still wondering why the form in
my Application won't display fieldError messages when I use only
Serverside validation.

If, on the s:form, I use validation="true" the javascript is included
to do validation, and the errorMessages automagically appear
(theme="xhtml")

However, if I don't use <s:form validation="true">  the validation
still works (page result is INPUT) but the error messages aren't
rendered.  When I create a simple "Hello World" app, it does work; and
I can't figure out which bit of Struts I've broken in trying to get my
application's validation to work.

On Thu, Dec 9, 2010 at 7:14 PM, Li Ying <li...@gmail.com> wrote:
> I think Michal was right.
>
> If you don't want execute validation for some Action Method, the
> annotation "@SkipValidation" is a good solution.

Sure.. but serverside validation (which is affected by the annotation
(either SkipValidation, or the interceptorref) works.

> And, in your case,
> I noticed that, your server side action is doing nothing when the
> [cancel] button clicked.
> I suggest you can put a html Link for your [cancel] button, instead of
> a submit button.

Right.. and a links works.. but I'm trying to understand how to get
the button to work, in case I have to use a cancel button either in
this case, or in the future.

>
> So, when it be clicked, browser will jump to the next page, and your
> form will not be submitted.
> And of cause, the validation will not be executed.
>



-- 
Greg Akins

http://insomnia-consulting.org
http://www.pghcodingdojo.org
http://pittjug.dev.java.net
http://twitter.com/akinsgre
http://www.linkedin.com/in/akinsgre

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


Re: Cancel in a form re: bypass Validation

Posted by Li Ying <li...@gmail.com>.
I think Michal was right.

If you don't want execute validation for some Action Method, the
annotation "@SkipValidation" is a good solution.

And, in your case,
I noticed that, your server side action is doing nothing when the
[cancel] button clicked.
I suggest you can put a html Link for your [cancel] button, instead of
a submit button.

So, when it be clicked, browser will jump to the next page, and your
form will not be submitted.
And of cause, the validation will not be executed.

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


Re: Cancel in a form re: bypass Validation

Posted by Greg Akins <an...@gmail.com>.
On Thu, Dec 9, 2010 at 3:26 PM, Michal Ciasnocha <mc...@struts.cz> wrote:
> Hi Greg,
>
> I use in my code @SkipValidation annotation for method which I don't want to
> validate. For me it is easier than use interceptors.
>
> @SkipValidation
> public String cancel() {
>    return SUCCESS;
> }
>
> The second part - redirect - I hope is correct.
>

I think the problem is coming down to whether I use validation=true on
the form.. If I don't, I'm not getting the errormessages/labels.. if I
do, then I get client-side javascript validated that isn't affected by
the serverside annotations.

Serverside validation is fine if I can figure out why the errormessage
labels are disappearing.. Seems like it might be a function of using
the Convention plugin.

-- 
Greg Akins

http://insomnia-consulting.org
http://www.pghcodingdojo.org
http://pittjug.dev.java.net
http://twitter.com/akinsgre
http://www.linkedin.com/in/akinsgre

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


Re: Cancel in a form re: bypass Validation

Posted by Michal Ciasnocha <mc...@struts.cz>.
Hi Greg,

I use in my code @SkipValidation annotation for method which I don't 
want to validate. For me it is easier than use interceptors.

@SkipValidation
public String cancel() {
     return SUCCESS;
}

The second part - redirect - I hope is correct.


Regards, Michal.

Greg Akins wrote on 9.12.2010 19:46:
> I need to have a "Cancel" button on a form that skips the validation
> (Struts 2.2.1).  This seems harder than it should be and maybe I'm
> missing something.
>
> I've read a few posts about this and ended using the validation
> interceptorref to get this to work.
>
> I've had problems getting the interceptorref mechanism to work
>
> @Action(value = "hello-world-cancel",
> 			interceptorRefs = { @InterceptorRef(value = "validation", params = {
> 					"excludeMethods", "cancel" })},
> 					results = { @Result(name = SUCCESS, location="/jsp/logon.jsp") })
> 	public String cancel() throws Exception {
> 		LOG.debug("Cancelled", "The form has been cancelled");
> 		return SUCCESS;
> 	}
>
> The problem is.. I've got this working as part of the Maven
> struts-archetype-starter application.  However, I can't manage to get
> the same thing working on my application
>
> Bother are using theme="xhtml".. but my application will only do the
> Error Messages and labels if the validate="true" is set on the form.
> However, setting the validate=true on the form forces client-side
> javascript to be built which is run everytime the form is submitted,
> even if it's submitted from the cancel button.
>
> The HelloWorld application looks like it's using serverside validation
> (since there isn't any javascript in the page.. but the error messages
> and labels still appear).
>
> Any thoughts on what I might be missing?