Set Preferences Example

portlet.xml

<portlet>
        <portlet-name>actionportlet</portlet-name>
        <display-name>ActionPortlet</display-name>
        <portlet-class>com.test.ActionPortlet</portlet-class>
        <init-param>
            <name>view-jsp</name>
            <value>/html/actionportlet/view.jsp</value>
        </init-param>
        <init-param>
            <name>edit-jsp</name>
            <value>/html/actionportlet/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>ActionPortlet</title>
            <short-title>ActionPortlet</short-title>
            <keywords></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>
package com.test;
 
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
 
/**
 * Portlet implementation class ActionPortlet
 */
public class ActionPortlet extends GenericPortlet {
 
    public void init() {
        viewJSP = getInitParameter("view-jsp");
        editJSP = getInitParameter("edit-jsp");
    }
 
    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {
 
        // Pass information from Action Phase to Render Phase
        actionResponse.setRenderParameter("state","Actioned.");
    }
 
    public void doView(
            RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {
 
        String state = renderRequest.getParameter("state");
        renderRequest.setAttribute("state", state);
        include(viewJSP, renderRequest, renderResponse);
    }
 
    // To set preferences
    public void doEdit(RenderRequest renderRequest,
            RenderResponse renderResponse) throws PortletException,
            IOException {
 
        include(editJSP, renderRequest, renderResponse);    
    }
 
    protected void include(
            String path, RenderRequest renderRequest,
            RenderResponse renderResponse)
        throws IOException, PortletException {
 
        PortletRequestDispatcher portletRequestDispatcher =
            getPortletContext().getRequestDispatcher(path);
 
        if (portletRequestDispatcher == null) {
            _log.error(path + " is not a valid include");
        }
        else {
            portletRequestDispatcher.include(renderRequest, renderResponse);
        }
    }
 
    protected String viewJSP, editJSP;
 
    private static Log _log = LogFactoryUtil.getLog(ActionPortlet.class);
 
}

edit.jsp:

Edit mode example
prefs.png
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License