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(){
var url = "<portlet:actionURL portletMode='edit'><portlet:param name='action' value='addGroup'/></portlet:actionURL>";
submitForm(document.<portlet:namespace />fm, url);
}
And in the code we can do like this:
@RequestMapping("EDIT")
@ActionMapping(params = "action=addGroup")
public void handleAddGroup(ActionRequest actionRequest, ActionResponse response) throws ResearchLibraryException, Exception {
PortletPreferences preferences = actionRequest.getPreferences();
// Add something to preferences
preferences.store();
}
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.
This shouldn't be much different with Liferay MVC portlets. You should invoke a Liferay RenderCommand or ActionCommand. Check out https://portal.liferay.dev/docs/7-0/tutorials/-/knowledge_base/t/mvc-render-command or https://portal.liferay.dev/docs/7-0/tutorials/-/knowledge_base/t/mvc-action-command
For example, the action command will be its own OSGi component:
with this URL generation: