I have a problem in combining two <html:form>. I had a single JSP with with different sections and one submit button. I split the JSP into two using tiles. Now I am showing the two JSP and the lower one has the submit button. Now I want the values from both the JSP's should be submitted on the click of that single button. How do I achieve this?
Note: onnsubmit above should be onsubmit. I had to misspell it to get past the JavaRanch filters.
Having said this, be aware that you may get some strange behavior. What's going to happen is that two different server threads will be spawned, and both of them will send a response back to the browser. It's anybody's guess which one will hit the browser first.
The only time I've used this technique is when each form was in a different frame within the same frameset, so they each returned to different frames and didn't interfere with each other. Tiles doesn't work that way. Even though Tiles makes the page look like it's divided into different frames, there's still only one actual frame.
Granted I don't understand what you're trying to do in your application, but at this point, I'm having a hard time believing you really need two different forms. If you're submitting them both at the same time anyway, it sounds to me like one would do. [ February 13, 2007: Message edited by: Merrill Higginson ]
i might not have got your problem correctly but i will take a shot. correct me if i am wrong. you have JSP1 and JSP2. JSP2 in some circumstances might not be visible but JSP1 will always be visible. instead of creating 2 separate formbeans you can use only one which has all the attributes of both the jsps. what you have to do now is on submit just call the action which you want depending on the situation.
hope this helps
to err is human, but the company policy doesn't allow it!
Joined: Feb 15, 2005
Originally posted by Me Mehta: Is there any way I can refer to the form of another JSP in my current jsp?
You mentioned in your first post that you're using Tiles to display the two JSPs together on the same page. If this is true, there is still only one physical HTML document containing two different forms. Struts automatically assigns the name of the form as the name of the ActionForm bean assigned to the Action you've declared for the form, so you're right, the name of both forms will be the same.
Alternately if you specify styleId="x" in the <html:form> tag, Struts will format that as id="x" when the actual html is rendered. If you do this, you can refer to the form like this:
var myForm = document.getElementById("x");
So yes, you can refer to one form from the other as long as they're physically present in the same document.
For example, suppose you only want to display part B when your ActionForm bean property "displayPartB", which is of type boolean is true. Just put the following at the end of the document just before the </body> tag.
Joined: Aug 03, 2006
Thanks for the reply again !! Its very informative for me.. Meanwhile I worked on your first advice (using a single form). I removed the form from both the JSP files and created a third JSP file with a single form. In that form I included the first two files and used <logic> tag for displaying/hiding the second one. This is working fine as now the same action is being used for both of them and both are submitted on submission of the form.