Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Trouble submitting form with 'onsubmit' handler defined

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 40198
816
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Have you tried:
HttpUnitOptions.setExceptionsThrownOnScriptError( false );
 
terrance grahn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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.
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic