In Liferay7, the control layer in the Portlet is split into 3 parts:
1.MVCActionCommand
2.MVCRenderCommand
3.MVCRecourceCommand
As for why to be torn out, before we write ActionURL, a JSP may have a lot of actionurl, is to write it in Mvcportlet class, when the code is large, not easy to manage, and the structure is not particularly clear.
The following is a brief introduction to the use of Mvcactioncommand, with a simple small example say Hi to U portlet
1. Build a common Mvc-portlet, previously thought Mvc-action-command is independent existence, is also silly ^ ^
This is the template generated by the Liferay IDE plug-in itself, casually explain, @Component the use of property properties.
1, Com.liferay.portlet.display-category: Here is the control in the Portlet management, when we add portlets, the portlet is displayed under which category. As shown, we have configured here under Category.sample, so we can see it under the application example when we click Add. Category.sample is a key value for internationalization, and if we want to define the classification ourselves, we can modify this value.
2. Com.liferay.portlet.instanceable: This configuration means whether the portlet is allowed to be added more than once on the same page, the default value is true, and we may only want the same portlet in some scenarios and only allow one at a time on the same page, then change this to false. Look at the front of the portlet is a small circle of the expression can only be added once, is the representation of nine small squares may be added more than once.
3, Javax.portlet.display-name: Display name, that is, we see above the name of the Portle.
4, Javax.portlet.init-param.template-path, this value defaults to "/", but also can only be "/", in the Mvcportlet class has been limited, if not error.
5, Javax.portlet.init-param.view-template=/view.jsp,portlet is dragged to the Liferay page after the default is to perform which JSP, this path is relative to Meta-inf/resource , we can modify the corresponding JSP path and name here.
6, Javax.portlet.resource-bundle=content. Language language internationalization support file, not required. If you want your portlet to support internationalization, you need to. In the Resource/content directory to build language_zh_cn.porperties files, in which to write the internationalization of Chinese. This content is followed by a blog detailed description.
7. Javax.portlet.security-role-ref=power-user,user: After the portlet is deployed, this portlet defaults which roles have permission to add this portlet to the page.
Note : The configuration here is more than just these, previous versions of Portlet.xml, Liferay-portlet.xml, Liferay-display.xml configuration properties have been moved here, so if you see that the tutorial is the corresponding configuration, in 7.0 is added here.
More configuration can refer to the source code inside the class: Portletpropertyvalidator
(The explanations here refer to the Hu Qishui Teacher's blog)
2. Then my goal is to do a portlet, after you enter the name, it will say hello to you, the effect is as follows:
3. First, what we want to do is to write a form in the view.jsp file that allows the user to enter values and trigger Actionrequest to process the returned data when the user taps the button.
var= "MyCommand" ></portlet:actionurl><form method= "post" action = "${mycommand}" ><p> What'syour name?</p><input type= "text" name= "name" ><input type= "Submit" value= "Tell Me" ></ Form>${greet}
4. The focus has come, how can you write the background of the Actioncommand and the front desk JSP connection, but also with your portlet?
Look at the code first and then explain:
PackageMvc.portlet.portlet;ImportCom.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;ImportCom.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;ImportCom.liferay.portal.kernel.util.ParamUtil;Importjavax.portlet.ActionRequest;ImportJavax.portlet.ActionResponse;Importorg.osgi.service.component.annotations.Component; @Component (Immediate=true, Property= { "Javax.portlet.name=mvc_portlet", "Mvc.command.name=greettou"},service= Mvcactioncommand.class) Public classMyactioncommandextendsBasemvcactioncommand {@Overrideprotected voidDoprocessaction (actionrequest actionrequest, Actionresponse actionresponse)throwsException {String name= Paramutil.getstring (actionrequest, "name"); Actionrequest.setattribute ("Greet", "Hi" + name+ ", nice to meet u!"); }}
Notice the two parameters above, portlet.name it with the portlet, and command.name it with the ActionURL on the JSP.
Then deploy to 7.0 of the portal up on it, clear the idea is not much easier, haha
The usage and examples of Liferay Mvcactioncommand