为什么Liferay Faces不处理JSF portlet动作事件?

时间:2014-11-28 18:18:25

标签: jsf liferay portletbridge

我在尝试使用Liferay Faces和任何JSF组件来触发动作事件时遇到问题。

我已经完成了Liferay的Developing JSF Portlets指令页的第一部分,直到(但不包括)Internationalize JSF Portlets部分成功。我继续并添加了一些其他JSF组件也取得了一些成功,但事件并没有起作用。

此示例的目标是有一个文本框,用户可以在其中更改“World”的默认文本,文本区域将通过AJAX在每次击键时更新“Hello,XXX”(其中XXX是文本)从箱子里)。是的,在一个单独的JSF项目中,我尝试了view.xhtml和TestBean.java,它可以工作。

在Liferay门户中,portlet显示,当我输入时,我收到回发到服务器。 DebugPhaseListener仅在RESTORE_VIEW 1之前/之后,在RENDER_RESPONSE之前或之后产生6.中间没有相位,我认为这表示问题。 (注意:Liferay Faces portlet桥接桥接portlet生命周期事件并模拟JSF生命周期。)

我正在使用Liferay 6.2,在Eclipse Luna中运行Liferay最新的Tomcat软件包以及来自Liferay更新站点的最新eclipse插件。 Java 1.7.0_71。

以下是我认为与确定正在发生的事情相关的所有资产和代码。您将给予的任何帮助将不胜感激。

view.xhtml:

<?xml version="1.0"?>

<f:view
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
>
    <h:head />
    <h:body>
        <h:form id="someForm">
            <p:calendar id="myCal" mode="inline" value="#{testBean.myDate}" actionListener="#{testBean.updateDate}">
                <p:ajax actionListener="#{testBean.updateDate}" update="myMsgs"/>
            </p:calendar>
            <br/>
            <p:commandButton value="Hi there" actionListener="#{testBean.updateDate}" update="myMsgs"/>
            <br/>
            <p:messages id="myMsgs"/>
            <br/>
            Test String=#{testBean.testString}
            <br/>
            Output Text test string = <h:outputText value="#{testBean.testString}"/>


            <h:outputLabel value="Name" for="nameInput" />
            <h:inputText id="nameInput" value="#{testBean.name}">
                <f:ajax render="output" event="keyup" />
            </h:inputText>
            <br/>

            <p>
                <h:panelGroup id="output">
                    <strong> <h:outputText value="Hello, #{testBean.name}" />
                    </strong>
                </h:panelGroup>
            </p>

            <h:commandButton id="reset" value="Reset"
                actionListener="#{testBean.reset}">
                <f:ajax render="@form" />
            </h:commandButton> - Reset The Form to "World"
            <br/>

            <h:messages />

        </h:form>
    </h:body>
</f:view>

TestBean.java

import java.io.Serializable;
import java.util.Date;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;


@ManagedBean(name="testBean")
@SessionScoped
public class TestBean
    implements Serializable
{
    private static final long serialVersionUID = 1L;

    public String getTestString()
    {
        return "Test String";
    }

    private Date myDate = new Date();
    public Date getMyDate() { return myDate; }
    public void setMyDate(Date value) { System.out.println("setMyDate value="+value); myDate = value; }

    public void updateDate()
    {
        System.out.println("updateDate - myDate="+myDate);
    }

    /**
     * Stores the name which will be used to greet the application user.
     */
    private String name;

    /**
     * Initializes {@link #name} with the value {@code "World"}.
     */
    @PostConstruct
    public void postContruct()
    {
        this.name = "World";
    }

    /**
     * Returns {@link #name}.
     *
     * @return {@link #name}
     */
    public String getName()
    {
        return name;
    }

    /**
     * Set {@link #name}.
     *
     * @param value
     */
    public void setName(String value)
    {
        System.out.println("Setting name to " + value);
        name = value;
    }

    /**
     * Resets {@link #name} to the default value {@code "World"}.
     *
     * @param ae
     * ignored
     */
    public void reset(ActionEvent ae)
    {
        setName("World");
    }
}

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>my-calendar-portlet</portlet-name>
        <display-name>My Calendar Portlet</display-name>
        <portlet-class>
            javax.portlet.faces.GenericFacesPortlet
        </portlet-class>
        <init-param>
            <name>javax.portlet.faces.defaultViewId.view</name>
            <value>/views/my-calendar-portlet/view.xhtml</value>
        </init-param>
        <init-param>
            <name>javax.portlet.faces.defaultViewId.edit</name>
            <value>/views/my-calendar-portlet/edit.xhtml</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>My Calendar Portlet</title>
            <short-title>My Calendar Portlet</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>
</portlet-app>

的liferay-portlet.xml中

<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">

<liferay-portlet-app>

    <portlet>
        <portlet-name>my-calendar-portlet</portlet-name>
        <icon>/icon.png</icon>
        <header-portlet-css>/css/main.css</header-portlet-css>
        <footer-portlet-javascript>
            /js/main.js
        </footer-portlet-javascript>
        <css-class-wrapper>
            my-calendar-portlet-portlet
        </css-class-wrapper>
    </portlet>
    <role-mapper>
        <role-name>administrator</role-name>
        <role-link>Administrator</role-link>
    </role-mapper>
    <role-mapper>
        <role-name>guest</role-name>
        <role-link>Guest</role-link>
    </role-mapper>
    <role-mapper>
        <role-name>power-user</role-name>
        <role-link>Power User</role-link>
    </role-mapper>
    <role-mapper>
        <role-name>user</role-name>
        <role-link>User</role-link>
    </role-mapper>
</liferay-portlet-app>

按下每个键的调试输出:

22:18:22,328 DEBUG [DebugPhaseListener:64] BEFORE phaseId=[RESTORE_VIEW 1] viewId=[null]
22:18:22,328 DEBUG [DebugPhaseListener:48] AFTER phaseId=[RESTORE_VIEW 1] viewId=[/views/my-calendar-portlet/view.xhtml]
22:18:22,328 DEBUG [DebugPhaseListener:64] BEFORE phaseId=[RENDER_RESPONSE 6] viewId=[/views/my-calendar-portlet/view.xhtml]
22:18:22,338 DEBUG [DebugPhaseListener:48] AFTER phaseId=[RENDER_RESPONSE 6] viewId=[/views/my-calendar-portlet/view.xhtml]

1 个答案:

答案 0 :(得分:1)

请将以下内容添加到 <portlet> WEB-INF/liferay-portlet.xml部分:

<requires-namespaced-parameters>false</requires-namespaced-parameters>

确保遵循DTD并按正确的顺序包含元素:https://docs.liferay.com/ce/portal/7.0-latest/definitions/liferay-portlet-app_7_0_0.dtd.html

例如,您的 liferay-portlet.xml <portlet>部分应如下所示:

<portlet>
    <portlet-name>my-calendar-portlet</portlet-name>
    <icon>/icon.png</icon>
    <requires-namespaced-parameters>false</requires-namespaced-parameters>
    <ajaxable>false</ajaxable>
    <header-portlet-css>/css/main.css</header-portlet-css>
    <footer-portlet-javascript>
        /js/main.js
    </footer-portlet-javascript>
    <css-class-wrapper>
        my-calendar-portlet-portlet
    </css-class-wrapper>
</portlet>