• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Trouble submitting form with 'onsubmit' handler defined

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpUnit1.6
Struts1.2.4

I am trying to submit a form (not a struts form though) via HttpUnit that is apparently having trouble because of the forms 'onsubmit' handler. It's a standard piece of javascript - I have verified that the javascript function exists. I guess it has issues with the 'return' or 'this' portions. I don't even care about testing the validation script in HttpUnit, I just want to submit the form, but everytime I get an exception (see below):



HttpUnit code


throws the following exception
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm. Where in the HTML document does the validateXxx() function reside?
 
terrance grahn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a snippet of the html document that contains the validate function (which is generated by the struts validator).
 
author & internet detective
Posts: 41093
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Terrance,
Does it work if you try submitting the form through the browser? I've never seen "this" passed as a parameter before. (which isn't to say it doesn't work.)

Regardless, try passing the explit form:
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Passing 'this' to a JavaScript onSubmit handler is the standard way of calling the Struts validation functions so it should work (also it's more cross-browser compatible than document.forms["myForm"], for example).
 
terrance grahn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, I originally used "document.loginForm" and had the same issue. Since I was in a time crunch I hacked a workaround. I created a 'dummy' form at the bottom of the HTML page that consists of the following:

Now, since this form only contains hidden parameters - in my HttpUnit test case I use a Scriptable handler to populate them and submit the form (HttpUnit will not let you directly change a hidden form parameter without throwing an exception).

Seems cheesy, but until I figure out what the hell is going on it will have to do. My hunch is that it has something to do with the fact that I am using <form> instead of <html:form>, but cannot verify.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried:
HttpUnitOptions.setExceptionsThrownOnScriptError( false );
 
terrance grahn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I now believe that this is a bug related to the DOM implementation that rhino.jar uses - basically the latest version of rhino cannot validate javascript functions that are generated by Struts. I'll try to find a link to the bug and post it here.
 
Your buns are mine! But you can have this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic