Liferay portlet中没有编辑模式

Joh*_*ers 6 java portlet liferay

我正在关注Liferay In Action书.我正处于将编辑模式添加到portlet的部分.portlet已成功部署,我已添加了portlet,现在该书说要单击portlet中的扳手并单击Preferences链接,但我没有Preferences链接.查看工作正常.

这是我的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>
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

我的doEdit方法:

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);
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*lin 3

要在 Liferay 中的 portlet 中拥有首选项(配置)页面,您必须com.liferay.portal.kernel.portlet.ConfigurationAction在 liferay-portlet.xml 中实现接口并配置 portlet 才能使用您的类。

<portlet>
  <portlet-name>MyPortlet</portlet-name>
  <configuration-action-class>com.mydomain.myportlet.ClassThatImplementsConfigurationAction</configuration-action-class>
  <instanceable>false</instanceable>
  ...
</portlet>
Run Code Online (Sandbox Code Playgroud)

您还应该知道,在该类中,您位于 Liferay 的配置 portlet 中,而不是您的 portlet 中。所以得到像这样的偏好

portletRequest.getPreferences();
Run Code Online (Sandbox Code Playgroud)

导致 Liferay-s 配置 portlet 的首选项。

要获取 portlet 的首选项,请将此方法添加到您的类中

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;
}
Run Code Online (Sandbox Code Playgroud)

并从实现的方法中调用它

public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception;

public String render(PortletConfig portletConfig, RenderRequest renderRequest,
        RenderResponse renderResponse) throws Exception;
Run Code Online (Sandbox Code Playgroud)