1

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

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

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

在 Liferay 门户中,portlet 显示出来,当我键入时,我得到了一个回发到服务器的信息。DebugPhaseListener 只导致 BEFORE/AFTER RESTORE_VIEW 1 和 BEFORE/AFTER RENDER_RESPONSE 6。两者之间没有阶段,我认为这表明存在问题。(注意:Liferay Faces Portlet 桥接 Portlet 生命周期事件并模拟 JSF 生命周期。)

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

以下是我认为与弄清楚发生了什么相关的所有资产和代码。您可以提供的任何帮助将不胜感激。

视图.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]
4

1 回答 1

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>
于 2014-12-30T11:41:52.090 回答