PORTLET PREFERENCE EXAMPLE


Portlet preferences:
<portlet>
    <portlet-name>my-portlet</portlet-name>
    <portlet-class>
        com.example.MyPortlet
    </portlet-class>

    <portlet-preferences>
        <preference>
            <name>my-first-pref</name>
            <value>some default value</value>
        </preference>
    </portlet-preferences>

</portlet>

To get the values:

<%@page import="javax.portlet.PortletPreferences"%>
<%@page import="javax.portlet.PortletRequest"%>
<%@page import="com.liferay.portal.util.PortalUtil"%>
<%@page import="javax.portlet.PortletContext"%>
<%@page import="javax.portlet.ActionRequest"%>

<%
 PortletPreferences pref =PortalUtil.getPreferences(request);
  String first=pref.getValue("my-first-pref ","");
%>
The preference i set was: <%=first%>

To set the values:
PortletPreferences pref=actionRequest.getPreferences();
pre.setValue("prefer", "hello preference");
pref.store();

Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.