PDA

View Full Version : multiple forms in JSP problem.


harry_m
Mar 15th, 2006, 10:11 AM
hi all,

i have a JSP that has multiple form elements. issue i am facing is that whenever i try to submit child form i.e. form nested inside parent form, it submits parent form and not child form.

maybe it has nothing to do with spring but i was wondering how spring stores binding of html's <form> action tag. we leave action attribute of <form> element blank but when submit, it goes to URL where GET request went to open form. Since HTTP is stateless, this binding must be getting stored somewhere on server.

back to problem, whichever button is clicked, it picks up parent form and submits it.

can anyone point me on how spring handles HTTP request(gone thru spring api doc for simpleformcontroller but didnt help) or any relevant doc or tell me solution(that will b simply great)

thnks in advance

kenevel
Mar 15th, 2006, 12:30 PM
Hi Harry,

I think I'm right in saying that this is nothing to do with Spring. AFAIK, there's no reason why you should be nesting html FORM elements in your JSP - and sorry to adopt a "thou shallt" attitude - but really, why have you done that? Forms are meant to be discrete sources of information to send back to the server. I can't think of a good reason to nest them!

If you can't un-nest the FORM elements, you could try giving each an ID attribute, then doing something like

<input type="button" onclick="document.getElementById('innerForm').submit()" value="my button"/>

Whether this will solve your problem I don't know - it's a cludge designed to help you out with the horrors of having nested your forms!

The FORM element without an action attribute is submitted by the browser to the current URL: nothing is stored on the server side. Unless you have a session-scoped form object, nothing is stored by Spring between controller invocations (correct me if I'm wrong here, folks).

Cheers

Mike

harry_m
Mar 16th, 2006, 04:48 AM
hi kenevel,
problem with me is that i cant use javascript (client guidelines), which means, i cant use onClick event in button.
scenario is - i want back button functionality. but since i cant use onClick, i am submitting it as a form action submit and thats why nested forms. i know approach is not correct. its a workaround.

but i am not able to understand why parent form is getting submitted.
nested form is

<form action="/context/backAStep.html" method="GET">
<input type="submit" class="bottomBackBut" value="back a step" />
</form>

i posted on spring forum becz i wanted to understand how form is submitted when we dont give action attribute? some header/meta data being set by DispatcherServlet , dont know.

if u or anyone have any suggestions, pls let me know.

harry_m
Mar 16th, 2006, 07:31 AM
hey, just found out that u cant nest HTML forms...u can have more than one in JSP but cant be nested.
makes sense too.

so that means my workaround wont work..will have to think of something else.

evartske
Sep 23rd, 2007, 10:36 PM
I am trying to find the best solution to my problem. I have a collections of object that display and have some editable fields, but I want to be able to select one and go to a detail page. I would be easy if you could nest html form inside a form, but this can't be done. Any Idea.