• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Submitting a struts form outside of the form body

 
Marcus Bowden
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I'm brand new here and fairly new to struts and jsp so go easy on me

I have a form that looks like this:



I want to be able to fire off one of the submits somewhere else in the page that is not inside this form. For example:



The above example doesn't work for me and using firebug console i get the error: "document.myform.submit() is not a function" //replacing myform with the actual form name

How do i do this? Any insight would be greatly appreciated and please forgive my rustyness with html/javascript/dom stuff too.

Cheers,

Marcus

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using the name 'submit' for any element in the form? I assume that's what the property="submit" does? (I wouldn't know, I'm not a Struts fan.)

If so, you have essentially wiped out the submit function.
 
Marcus Bowden
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Are you using the name 'submit' for any element in the form? I assume that's what the property="submit" does? (I wouldn't know, I'm not a Struts fan.)

If so, you have essentially wiped out the submit function.


My only elements in this form that might wipe out the submit function are:



Ill change em up and give that a try.
 
Marcus Bowden
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html:submit property="foo"> just renders and html <input> element with type=submit. Having two of them could be problematic i guess.

The property attribute is the name of the request parameter that will be included with this submission, set to the specified value.

These definitions are from the struts framework page and its kind of confusing to me but the two <html:submit...>'s i have a functional at present doing their own functions and changing their property from submit breaks them.

Is there anyway to call these from outside the form?
 
Roberto Hernandez
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would have to invoke a javascriipt function to submit your form


then in your button, declare an onclick attribute:



make sure you give your form a "Name" and "Id" that way you can get the form element
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto Hernandez wrote:You would have to invoke a javascriipt function to submit your form

Won't work. The point is that by naming a form element "submit", the JavaScript submit() function is blown away! See next post...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Struts forces you to name form elements "submit" then Struts is seriously broken as "submit" is a reserved name. Using it replaces the submit() function with the named element, rendering it impossible to call the function.

You should check into that enforced naming as I'm having a hard time believing that, much as I loathe Struts, it could be so short-sighted.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it turns out that Struts really does force you to use invalid names, there's a completely barf-able work-around:

After the <form> tag but before the offending elements:

This creates an alias to the submit() function before it gets blown away. You can then submit the form by calling the aliased function.

If that doesn't make you lose your lunch, nothing will.
 
Marcus Bowden
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to clairify, my struts-config.xml file does allow for multiple submits in a form. Each one's value is what determines the next mapping. It's really more of how i can achieve that same functionality but just outside of the form.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has nothing to do with having multiple submit elements, and everything to do with the fact that any (one, two, or seventeen) elements have a name attribute of "submit".

Have you looked at the HTML being generated by Struts? Does any element have a name="submit" attribute? If so, you need to figure out how to have that not happen, or resort to the completely disgusting and ridiculous work-around that I posted.
 
Marcus Bowden
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh i see.

Well thanks for the insight Bear, much appreciated. I'm going to try a few things and ask the original writers if they have some ideas.

Cheers
 
Marcus Bowden
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I broke down and put a the buttons in a div (absoloutly positioned to where i needed)

Its a bit better than aliasing the submit type...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic