• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Client-side javascript validation not working with Struts

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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" />
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
---
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic