John Powers
John Powers

Reputation: 267

No edit mode in Liferay portlet

I'm following along with the Liferay In Action book. I'm at the part where I am adding edit-mode to a portlet. The portlet deployed successfully and I've added the portlet and now the book says to click the wrench in the portlet and click the Preferences link but I don't have a Preferences link. View is working 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);
}

Upvotes: 6

Views: 4592

Answers (3)

Karadous
Karadous

Reputation: 1635

Check if you have changed the portlet.xml file correctly. Especially check the support tag.

Upvotes: 0

David
David

Reputation: 4285

<portlet-class>com.liferaytest.portlet.HelloJohnPortlet</portlet-class>

In case this class extends the genericportlet class make sure your editJSP string matches "edit-jsp" in your init method.

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

If its MVCPortlet It should show correctly.

The following actions are not directly related to your problem but there is a possibility the problem can be solved by checking the following 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 libs (util-java.jar, util-taglib.jar, util-bridge.jar , portlet.jar)
  • Shutdown the Server
  • Delete everything under work folder (of your tomcat server)
  • Start your Server
  • Redeploy the portlet
  • If You are autologed in , try relogging.
  • The preferences menu should now be visible.

Upvotes: 0

Martin Gamulin
Martin Gamulin

Reputation: 3865

To have preferences(configuration) page in your portlet in Liferay you must implement com.liferay.portal.kernel.portlet.ConfigurationAction interface and configure portlet in liferay-portlet.xml to use you class.

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

You should also be aware that inside that class you are in Liferay's configuration portlet, not your portlet. So getting preferences like

portletRequest.getPreferences();

results in preferences of Liferay-s configuration portlet.

To get preferences 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 implemented methods

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

public String render(PortletConfig portletConfig, RenderRequest renderRequest,
        RenderResponse renderResponse) throws Exception;

Upvotes: 3

Related Questions