aspose file tools*
The moose likes Struts and the fly likes Client-side javascript validation not working with Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Client-side javascript validation not working with Struts" Watch "Client-side javascript validation not working with Struts" New topic
Author

Client-side javascript validation not working with Struts

Amy Smith
Greenhorn

Joined: Jul 26, 2001
Posts: 24
Hi all,
I have Struts1.1 rc1 installed. Using DynaValidatorActionForm and attempting to do javascript validation in addition to the server validation. Server validation works fine. However, the javascript that is generated has "function validate/displayOptions(form)".
It appears that because you use the path instead of the form name, the javascript will not work.
Has anyone else experienced this or found what is wrong?
Thanks,
Amy
------struts-config.xml-------
<form-bean name="optionsForm" type="org.apache.struts.validator.DynaValidatorActionForm">
<form-property name="option" type="java.lang.String" />
<form-property name="options" type="java.util.Vector" />
</form-bean>
<action name="optionsForm" path="/displayOptions" scope="request" input="/request_options.jsp" type="com.hermanmiller.sample.struts.actions.DisplayOptionsAction">
<forward name="success" path="/options.jsp" />
</action>
--------validation.xml---------
<form name="/displayOptions">
<field property="option" depends="required,integer">
<arg0 name="required" key="option.id"/>
<arg0 name="integer" key="option.id"/>
</form>
----------jsp------------
<html:javascript formName="/displayOptions" />


Amy Smith<br />Java Developer<br />Haworth, Inc.<br />amy.smith@haworth.com
Miles Daffin
Greenhorn

Joined: Mar 20, 2003
Posts: 4
I reckon this must be a bug - and a pretty reasonable one. I will raise it at the struts site.
Miles Daffin
Greenhorn

Joined: Mar 20, 2003
Posts: 4
Amy,

I posted this same problem to the struts-users mail group and got this reply from David Friedman (tried & tested):

---
Miles,

Validation based on actions has that slash-in-the-name related problem. You can specify a name for the validation method using the html:javascript attribute method="...". Just be sure to change your html:form's onsubmit to invoke that new method name. For example:

<html:javascript formName="/someActionName" method="validateForm" /> <html:form action="..." ... onsubmit="return(validateForm(this));">

Just use the name "validateForm" or change it to any valid JavaScript method name of your choice. For more details see:

http://forum.java.sun.com/thread.jspa?forumID=45&messageID=2674439&threadID=
548445
http://homepage2.nifty.com/ymagic/struts/OtherTranslate/StrutsValidator/jspt
ags-jp.html

Regards,
David
---
Cliff Edwards
Greenhorn

Joined: Mar 22, 2004
Posts: 16
Another possible reason for this problem is that switching from HTML to XHTML will break the client-side validation. I have verified this. Please reference this link: http://galaxy.andromda.org/forum/viewtopic.php?t=540.

The solution is to remove "<html:xhtml/>" from the JSPs that are involved with validation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Client-side javascript validation not working with Struts