File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

Client-side javascript validation not working with Struts

Amy Smith

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?
<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" />
<action name="optionsForm" path="/displayOptions" scope="request" input="/request_options.jsp" type="com.hermanmiller.sample.struts.actions.DisplayOptionsAction">
<forward name="success" path="/options.jsp" />
<form name="/displayOptions">
<field property="option" depends="required,integer">
<arg0 name="required" key=""/>
<arg0 name="integer" key=""/>
<html:javascript formName="/displayOptions" />

Amy Smith<br />Java Developer<br />Haworth, Inc.<br />
Miles Daffin

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

Joined: Mar 20, 2003
Posts: 4

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


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:

Cliff Edwards

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:

The solution is to remove "<html:xhtml/>" from the JSPs that are involved with validation.
I agree. Here's the link:
subject: Client-side javascript validation not working with Struts
It's not a secret anymore!