On Sun, 2004-08-15 at 00:19, Jacob Weber wrote:
> I have a JSP with two forms, and they both need to go to the same
> action. But Struts assumes that the "name" property of the HTML form
> (e.g. <FORM NAME="MYFORM">) should be the same as the name of the
> associated form bean. As a result, I can't use JavaScript to refer to
> one of the forms, since they both have the same name.
>
> Is this a situation where I need to write my own version of <html:form>?
> Why does Struts make this assumption?
>
> Things I've already considered:
>
> - Using two different actions with different form beans. This doesn't
> work, since the JSP needs to refer to the form bean by name (for
> example, in <bean:write>). If I use two actions that return the same
> JSP, they need to use the same form bean.
Why can't you do this?
in MyAction.java
String formName = mapping.getAttribute();
request.setAttribute("formName", formName);
Struts.config.xml
<form-beans>
<form-bean name="form1" type="foo.MyForm" />
<form-bean name="form2" type="foo.MyForm" />
<form-beans>
<action-mappings>
<action path="/myFirstPath" type="foo.MyAction" name="form1">
<forward name="success" path="somewhere" />
<forward name="failure" path="somewhere_else" />
</action>
<action path="/mySecondPath" type="foo.MyAction" name="form2">
<forward name="success" path="somewhere" />
<forward name="failure" path="somewhere_else" />
</action>
</action-mappings>
On the HTML/JSP page
do all your bean writes according to the value of
<%
String name = request.getAttribute("formName");
foo.MyForm theForm = request.getAttribute(name);
%>
<bean:write name="theForm" property="whatever"/>
<!-- these get processed by the same action, and use the same type of
ActionForm -->
<form name="form1" action="/myFirstPath.do"> etc. </form>
<form name="form2" action="/mySecondPath.do"> etc. </form>
--
Matthew Van Horn <[EMAIL PROTECTED]>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]