简体   繁体   中英

How to see portlet configuration page in Liferay?

When creating portlet in Liferay IDE, I have configured it to have Liferay's configuration mode. In response, the wizart created JSP file with the following text:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

This is the <b>MyPortlet</b> portlet in Config mode.

How to call this page from Liferay to see this text? When clicking wrench icon and selecting Configuration I see nothing similar.

UPDATE

Path is set correctly because it was set by wizard.

The question is how to call this JSP from web interface by a mouse?

Usually the problem is that the path to the configuration jsp is not properly set.

In portlet.xml

Add the following:

<init-param>
    <name>config-template</name>
    <value>/path/to/configuration.jsp</value>
</init-param>

as a child of the <portlet> element that corresponds to the portlet you're trying to modify.

Your final portlet.xml should look something like:

<portlet-app>
    <portlet>
        <portlet-name>my-portlet</portlet-name>
        <display-name>My Portlet</display-name>
        <portlet-class>com.liferay.portlet.StrutsPortlet</portlet-class>
        <init-param>
            <name>config-template</name>
            <value>/path/to/configuration.jsp</value>
        </init-param>
        <init-param>
            <name>view-action</name>
            <value>/my_portlet/view</value>
        </init-param>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
        </supports>
    </portlet>
</portlet-app>

From the wiki (no shame here though, took me a very long time to find it):

Add Config Page to Plugin Portlet <- get more info here

liferay-portlet.xml->

    <portlet>
      <portlet-name>configuration-example</portlet-name>
      <icon>/icon.png</icon> 
      <configuration-action-class>com.sample.jsp.action.ConfigurationActionImpl</configuration-action-class> 
      <instanceable>true</instanceable> 
      <header-portlet-css>/css/test.css</header-portlet-css> 
      <footer-portlet-javascript>/js/test.js</footer-portlet-javascript> 
    </portlet>

ConfigurationActionImpl.java (or your class)->

    public class ConfigurationActionImpl implements ConfigurationAction {
        public void processAction(PortletConfig config, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { 

          String portletResource = ParamUtil.getString(actionRequest, "portletResource"); 

          PortletPreferences prefs = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource); 

          //Read, validate, and then set form parameters as portlet preferences

          prefs.store();

          SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
        }
        public String render(PortletConfig config, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception { 

        return "/configuration.jsp";
        }
    }

Configuration.jsp

    <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
    <%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>

    <portlet:defineObjects />

    <form action="<liferay-portlet:actionURL portletConfiguration="true" />" method="post" name="<portlet:namespace />fm"> <input name="<portlet:namespace /><%=Constants.CMD%>" type="hidden" value="<%=Constants.UPDATE%>" /> 

    Type: <select name="<portlet:namespace />type"> <option value="casual">Casual</option> <option value="formal">Formal</option> </select> <br/>

    <input type="button" value="Save" onClick="submitForm(document.<portlet:namespace />fm);" /> </form>

"Note the portletConfiguration attribute in the liferay-portlet:actionURL tag."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM