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.
However, in JavaScript there is always more than one way to refer to something. If you know there are only two forms on the page, you can refer to them as elements of an array like this:
document.forms[0]
document.forms[1]
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.
Having answered your question, here's how I'd do it: I say that the fact you want some information to be displayed sometimes and not others is not a good enough reason to split it into two separate forms. Using CSS attributes you can make part of the page invisible even though it's still there in the document. I'd suggest keeping everything in the same JSP and the same form, but using CSS attributes to hide part of the document. You can then use JavaScript code to un-hide it when appropriate. Example:
When you want to un-hide it, execute the following JavaScript code:
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.