wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts 2.1 form validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2.1 form validation" Watch "Struts 2.1 form validation" New topic
Author

Struts 2.1 form validation

E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
I have tried using theme xhtml css_html and ajax for form validation. Each of these modifies the DOM and returns the error in the form. Is there a way to force one of these to provide javascript alert errors?

My form tag has:



I cant find any examples that show how to get a javascript alert() instead of the dom being altered using struts 2.1.8.

Im going to try posting to some other boards like java guru. I see examples of javascript alerts using struts 1 html:form but for the life of me I cant figure out how to get a javascript alert with s:form. The validation always alters the DOM and returns the message in the page instead of a js alert.

Thanks
Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

I think I answered this on your other post. But basically I think you will need to modify the source code and compile your version of whatever class is rendering the html/javascript or you will need to do some slick event listening for the DOM change where that javascript will supress the modification and instead pop up the error message in an alert. You can probably figure out how to do this with jQuery or YUI events.

E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
Hey Lucas,
I saw that I closed out that posting as it related to javascript validation & struts was acting as expected. I didnt ask the correct question which is how can I get a javascript alert from struts validation instead of having the javascript manipulate the DOM & insert the errors in the page.

You mention jQuery or YUI which I think is way to much overhead for validating 3 fields. Also you mention you dont think its possible out of the struts box.

I have been googling for hours and it looks like something that was possible with struts 1. (http://www.vaannila.com/struts/struts-example/struts-client-side-java-script-validation-example-1.html)

Additionally I am having a hard time getting my mind around the struts 2.1.8 developers giving me a 207 meg download and not thinking at some point I might want a javascript alert() for an error instead of everything going to the dom.

As you say it may not be possible out of the box for struts 2.1.8 to give a javascript alert() instead of altering the dom but if thats the case its time to shop for a different framework. Personally I think its possible and I just dont know how to do it and there are no examples. Ive been going back through the Apache documentation to see if it is documented somewhere.

Thanks,
Earl
E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
Its appears in struts 1 this functionality was provided or provided as a plugin. I just cant find it in struts 2

"...
<html:javascript formName="contactForm" dynamicJavascript="true" staticJavascript="true"/>
...
<html:form action="/contactSubmit" ...
onsubmit="return validateContactForm(this);">
...

"

http://www.oranda.com/webapp/struts1.html

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2.1 form validation
 
Similar Threads
Struts 2.1 javascript field validate
Struts 2.1 error message breaks page html formatting
struts validator
Struts 2.1.8 validation.xml & internationalization
Struts 2.1 xhtml forms rendering invalid html