Is there any way to pre-populate multiple forms with Struts and make them available to the JSP page?
I am building a page that has two different forms on it, that needs a custom data pre-populated from the database.
Both forms have to be on the same page.
Yes, it's possible.
You could specify multiple ActionForm
implementations for this issue (preferred) or use only one - no matter.
<nested:root name="myFirstForm">
<nested:form action="/MyAction.do?method=foo" method="post">
<%-- some code --%>
</nested:form>
<nested:form action="/MyAction.do?method=bar" method="post">
<%-- some code --%>
</nested:form>
</nested:root>
<nested:root name="mySecondForm">
<nested:form action="/MyAction.do?method=foobar" method="post">
<%-- some code --%>
</nested:form>
</nested:root>
From Apache Struts Newbie FAQ:
Q: Do I have to have a separate ActionForm bean for every HTML form?
A: This is an interesting question. As a newbie, it is a good practice to create a new ActionForm for each action sequence.