RE: Multiple actions in edit mode

Sarath Chandra, modified 5 Years ago. New Member Posts: 9 Join Date: 10/28/19 Recent Posts
I am following the following example: https://github.com/liferay/liferay-blade-samples/blob/7.1/maven/apps/configuration-action/src/main/java/com/liferay/blade/samples/configurationaction/MessageDisplayConfigurationAction.java
I have multiple submit buttons in my form. I'd like to handle them in multiple methods. This is possible in Spring MVC Portlet. For example, you can do this: Attach an onlclick event of the button to a function that looks like this: 
function <portlet:namespace />addGroup(){
&nbsp;&nbsp; &nbsp;var url = "<portlet:actionurl portletmode="edit"><portlet:param name="action" value="addGroup" /></portlet:actionurl>";
&nbsp;&nbsp; &nbsp;submitForm(document.<portlet:namespace />fm, url);
}

And in the code we can do like this: 
&nbsp; &nbsp; @RequestMapping("EDIT")
&nbsp;&nbsp; &nbsp;@ActionMapping(params = "action=addGroup")
&nbsp;&nbsp; &nbsp;public void handleAddGroup(ActionRequest actionRequest, ActionResponse response) throws ResearchLibraryException, Exception {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;PortletPreferences preferences = actionRequest.getPreferences();
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Add something to preferences
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;preferences.store();
&nbsp;&nbsp; &nbsp;}

How to do the same thing in Liferay MVC. I would like to use multiple methods. Right now, I can do only one method and switch based on the condition and identify the different clicks.
thumbnail
David H Nebinger, modified 5 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
I can think of a number of ways...

So first one includes a <portlet:actionUrl /> with mvc action default for the value. JS bound to the button sets the mvc action and submits the form. The action handler component is bound to the defined paths and routing just works.


Next uses a regular <portlet:actionUrl /> for the form to submit, but the buttons then are form field values. The action handler component extracts the value and routes to separate methods or components for the options.

Last assumes that buttons do not, in fact, need to be bound to form submission, and just need a key value to do their own thing (like an edit and delete button in a row of data only needs the id). In these cases, they have their own actionUrl guys w/ their own parameters and routing is just done as normal.
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Sarath Chandra:

I am following the following example...
Please don't crosspost this in future or link your crossposts. A nice summary of the reasons is here.