Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Client-side javascript validation not working with Struts

 
Amy Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" />
 
Miles Daffin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I reckon this must be a bug - and a pretty reasonable one. I will raise it at the struts site.
 
Miles Daffin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic