submitting a single form among multiple forms

thumbnail
3838521, modified 16 Years ago. Regular Member Posts: 137 Join Date: 8/20/09 Recent Posts
Hi team,
I' Mdeveloping simple jsp-jdbc portlet.
In the View.jsp I'm having various forms. like,
<form method="POST" action="<portlet:actionURL/>" name="form1"> </form>
<form method="POST" action="<portlet:actionURL/>" name="form2"> </form>
<form method="POST" action="<portlet:actionURL/>" name="form3"> </form>


But whenever I click on submit button of any of the above form, the processAction() method will be invoking.
But how to invoke a particular form.

My idea was, getting the form name in processAction() method and, based on that we need to perform the actions (using if,else).

Is it a right way? If yes, Can anyone suggest me how to get the form name in procesAction() method of my Portlet ?

If the above process is completely wrong, Please suggest me the right wat to achieve this.

Thanks in advance.

Regards,
Giri
thumbnail
3838521, modified 16 Years ago. Regular Member Posts: 137 Join Date: 8/20/09 Recent Posts
hi team,
Please respond. It is a bit urgent.
thumbnail
552936, modified 16 Years ago. Liferay Legend Posts: 1902 Join Date: 3/10/08 Recent Posts
You could probably use a hidden input.
thumbnail
10527, modified 16 Years ago. Liferay Legend Posts: 1197 Join Date: 2/8/05 Recent Posts
Rather than having many forms we tupically have a hidden form field:

<input name="<portlet:namespace/>cmd" type="hidden" value="<%= (entity != null ? &quot;update&quot; : &quot;add&quot;) %>">


then in the html if we have several different operations, these are typically invoked by different buttons calling some javascript method which changes the value of "cmd":


<input type="submit" value="<liferay-ui:message key=" save">" /&gt;
<input type="button" value="<liferay-ui:message key=" expire">" onClick="<portlet:namespace />expire();" /&gt;
<input type="button" value="<liferay-ui:message key=" download">" onClick="<portlet:namespace />downloadContent();" /&gt;


the javascript functions look something like this:

	function <portlet:namespace />expire() {
		document.<portlet:namespace />fm1.<portlet:namespace />cmd.value = "expire";
		submitForm(document.<portlet:namespace />fm1);
	}


Now later in the processAction method:

		String cmd = ParamUtil.getString(actionRequest, "cmd");

			if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
				article = updateArticle(actionRequest);
			}

			...


Simple enough?
thumbnail
3838521, modified 16 Years ago. Regular Member Posts: 137 Join Date: 8/20/09 Recent Posts
hi Ray Augé / Samuel Kong,
Thanks for your support. This working great.

Special thanks to Ray, for providing such a useful code snippet.

now, everything working great.

Regards,
giri