No editing mode in Liferay portlet

I follow the book Liferay In Action. I am in the part where I add editing mode to the portlet. The portlet was successfully deployed, and I added the portlet, and now the book says to click the key in the portlet and click the "Settings" link, but I do not have the "Settings" link. Viewing works fine.

Here is my portlet.xml :

 <?xml version="1.0"?> <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0"> <portlet> <portlet-name>hello-john</portlet-name> <display-name>Hello John</display-name> <portlet-class>com.liferaytest.portlet.HelloJohnPortlet</portlet-class> <init-param> <name>view-jsp</name> <value>/view.jsp</value> </init-param> <init-param> <name>edit-jsp</name> <value>/edit.jsp</value> </init-param> <expiration-cache>0</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>view</portlet-mode> <portlet-mode>edit</portlet-mode> </supports> <portlet-info> <title>Hello John</title> <short-title>Hello John</short-title> <keywords>Hello John</keywords> </portlet-info> <security-role-ref> <role-name>administrator</role-name> </security-role-ref> <security-role-ref> <role-name>guest</role-name> </security-role-ref> <security-role-ref> <role-name>power-user</role-name> </security-role-ref> <security-role-ref> <role-name>user</role-name> </security-role-ref> </portlet> 

My edit.jsp :

 <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> <jsp:useBean class="java.lang.String" id="addNameURL" scope="request" /> <portlet:defineObjects /> <form id ="<portlet:namespace />helloForm" action="<%= addNameURL %>" method="post"> <table> <tr> <td>Name:</td> <td><input type="text" name ="username"></td> </tr> </table> <input type="submit" id="nameButton" title="Add Name" value="Add Name"> </form> 

My doEdit method:

 public void doEdit(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { renderResponse.setContentType("text/html"); PortletURL addNameURL = renderResponse.createActionURL(); addNameURL.setParameter("addName", "addName"); renderRequest.setAttribute("addNameURL", addNameURL.toString()); include(editJSP, renderRequest, renderResponse); } 
+6
source share
3 answers

To have a settings page in your portlet in Liferay, you must implement the com.liferay.portal.kernel.portlet.ConfigurationAction interface and configure the portlet in liferay-portlet.xml to use your class.

 <portlet> <portlet-name>MyPortlet</portlet-name> <configuration-action-class>com.mydomain.myportlet.ClassThatImplementsConfigurationAction</configuration-action-class> <instanceable>false</instanceable> ... </portlet> 

You should also know that inside this class you are in the Liferay configuration portlet, and not in your portlet. Thus, obtaining preferences such as

 portletRequest.getPreferences(); 

leads to the preferences of the Liferay configuration portlet.

To get the settings of your portlet, add this method to your class

 protected PortletPreferences getPortletPreferences(final PortletRequest p_portletRequest) throws Exception { String portletResource = ParamUtil.getString(p_portletRequest, "portletResource"); PortletPreferences prefs = PortletPreferencesFactoryUtil.getPortletSetup(p_portletRequest, portletResource); return prefs; } 

and call it from the implemented methods

 public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception; public String render(PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception; 
+3
source
 <portlet-class>com.liferaytest.portlet.HelloJohnPortlet</portlet-class> 

If this class extends the genericportlet class, make sure the editJSP line matches "edit-jsp" in your init method.

 public void init() throws PortletException { editJSP = getInitParameter("edit-jsp"); viewJSP = getInitParameter("view-jsp"); } 

If its MVCPortlet should display correctly.

The following steps are not directly related to your problem, but there is a possibility that the problem can be solved by following these steps.

  • Use the correct taglib:
 <%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> 
  • point it to the right .tld in your web.xml
  • Include the correct lib libraries (util-java.jar, util-taglib.jar, util-bridge.jar, portlet.jar)
  • Server shutdown
  • Delete everything in the working folder (your tomcat server)
  • Start the server
  • Redeploying a portlet
  • If you are authorized, try reinstalling.
  • Now the settings menu should be visible.
0
source

Verify that you have modified the portlet.xml file correctly. Especially check out the support tag.

0
source

Source: https://habr.com/ru/post/908364/


All Articles