MVC Action Command

 We can create liferay mvc portlet in two ways . 

1) Writing all lifecycle methods( render , action , resouce  ) in single portlet class
If you have a small application that won’t be heavy on controller logic , you can put all your controller code in the -Portlet class

2) Will divide the controller into MVC Action Command classes, MVC Render Command classes, and MVC Resource Command classes.

We are familiar with the first Approach . Lets explore  on the second approach .  

We have two scenarios 

1) Creating new Action Command for our custom portlet . 

--> Create new module project with mvc-portlet template  and project name "sample-portlet"

-->create a action url in jsp 

<portlet:actionURL  name="/samplePortlet/addEntity" var="addEntityURL" >

                <portlet:param name="Entity" value="1234" />

</portlet:actionURL>


-->Create  SampleActionCommand class which extends  BaseMVCActionCommand

Below important points to note here . 

i) portlet name : We need to provide the name of the portlet we want to customize . 

ii) mvc command name : The "name" parameter which we used in <portlet:actionURL> tag

iii) override the method  doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) : We need to override the method doProcessAction and implement the business logic here . 


@Component(

property = {

// portlet name 

"javax.portlet.name=com_liferay_command_SamplePortlet",

//command name which we given in <portlet:actionURL tag

"mvc.command.name=/samplePortlet/addEntity"

}, 

service = MVCActionCommand.class)

public class SampleActionCommand extends BaseMVCActionCommand {

@Override

protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

_log.info(" SampleActionCommand ----------doProcessAction");

System.out.println("SampleActionCommand ----------doProcessAction");

}

 complete code git location

2)Customizing the existing Action command  






Comments

Popular posts from this blog

Liferay 7.3 scheduler Entry