Liferay Faces为什么不处理JSF Portlet操作事件? [英] Why isn't Liferay Faces processing JSF portlet action events?

查看:133
本文介绍了Liferay Faces为什么不处理JSF Portlet操作事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试将Liferay Faces与任何JSF组件一起触发动作事件时遇到问题.

I am having issues with trying to use Liferay Faces along with any JSF components to fire action events.

我已经阅读了Liferay的

I've gone through the first part of Liferay's Developing JSF Portlets instruction page up until (but not including) the Internationalize JSF Portlets section with success. I went ahead and added some other JSF components with some success as well, however, events are not working.

此示例的目标是要有一个文本框,用户可以在其中更改默认文本"World",并且每次键入"Hello,XXX"(其中XXX是文本)时,AJAX都会通过AJAX更新文本区域.从盒子里).是的,在一个单独的JSF项目中,我已经尝试过view.xhtml和TestBean.java,并且可以正常工作.

The goal of this example is to have a text box where the user can change the default text of "World", and a text area will update by AJAX on every keystroke with "Hello, XXX" (where XXX is the text from the box). Yes, in a separate JSF project I have tried out the view.xhtml and TestBean.java and it works.

在Liferay门户中,portlet出现,当我键入内容时,我将回发到服务器. DebugPhaseListener仅导致BEFORE/AFTER RESTORE_VIEW 1和BEFORE/AFTER RENDER_RESPONSE6.两者之间没有阶段,我认为这表明了问题. (注意:Liferay Faces portlet桥桥接了portlet生命周期事件并模拟JSF生命周期.)

In the Liferay portal, the portlet shows up and when I type I am getting a postback to the server. The DebugPhaseListener is resulting in only BEFORE/AFTER RESTORE_VIEW 1, and BEFORE/AFTER RENDER_RESPONSE 6. There are no phases in between, which I presume is indicative of the problem. (Note: The Liferay Faces portlet bridge bridges the portlet lifecycle events and emulates the JSF lifecycle.)

我使用的是Liferay 6.2,它通过Liferay更新站点上的Liferay最新的Tomcat捆绑包和最新的eclipse插件在Eclipse Luna中运行. Java 1.7.0_71.

I am using Liferay 6.2, running in Eclipse Luna with Liferay's latest Tomcat bundle and latest eclipse plugin from the Liferay update site. Java 1.7.0_71.

这里是我认为与找出正在发生的事情有关的所有资产和代码.您能提供的任何帮助将不胜感激.

Here are all of the assets and code that I think are relevant to figure out what is going on. Any help you can give would be greatly appreciated.

view.xhtml:

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

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

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

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]

推荐答案

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

Please add the following to the <portlet> section of your 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 .

Make sure you follow the DTD and include elements in the correct order: https://docs.liferay.com/ce/portal/7.0-latest/definitions/liferay-portlet-app_7_0_0.dtd.html.

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

For example, your liferay-portlet.xml <portlet> section should look like this:

<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>

这篇关于Liferay Faces为什么不处理JSF Portlet操作事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆