p:ajax功能在Liferay门户中不起作用 [英] p:ajax feature not working in Liferay portal

查看:83
本文介绍了p:ajax功能在Liferay门户中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用liferay门户时,我无法使PrimeFaces 6.1内置的ajax功能正常工作.我从最开始的用例示例开始,即PF用户指南文档中显示的示例,什么也没有发生,绝对没有任何事情.

I can't get the PrimeFaces 6.1 built-in ajax feature to work when using a liferay portal. I've started with the very initial use case example, that is the one shown in the PF User's Guide documentation and nothing happens, absolutely nothing happens.

xhtml边

<h:form id="form">
    <h:inputText value="#{bEntityTree.text}">
        <p:ajax process="@form" update="output" onstart="onStart" oncomplete="onComplete" onsuccess="onSuccess" onerror="onError"/>         
    </h:inputText>
    <br/>
    <h:outputText id="output" value="valor:#{bEntityTree.text}"/>           

</h:form>

豆角:

@ManagedBean(name = "bean")
@ViewScoped
public class Bean implements Serializable {

private static Logger logger = Logger.getLogger(BEntityTree.class);

private String text;

public Bean() {
    logger.trace("bean created");
}

@PostConstruct
private void onPostConstruct() {
    logger.trace("start");
}

public String getText() {
    logger.trace("getting text:" + text);
    return text;
}

public void setText(String text) {
    logger.trace("setting text:" + text);
    this.text = text;
}
}

JS方面:

function onStart(){
    console.log("onStart"); 
}

function onComplete(){
    console.log("onComplete");
}

function onSuccess(){
    console.log("onSuccess");
}

function onError(){
    console.log("onError");
}

根据文档说明,每次输入更改时,都会将ajax请求发送到服务器.我的理解是,在触发"onchange"事件(默认客户端事件)时,输入会发生变化.好吧,每次我在<h:inputText>元素中键入一个字符时,都不会发生任何事情.当<p:inputText>失去焦点时,什么也没有发生,也就是说,<h:outputText>没有更新,并且任何跟踪控制台都显示在chrome浏览器的控制台上.我获得的唯一跟踪日志是从IDE控制台获取的跟踪日志:

According to what the documentation states, each time the input changes an ajax request is sent to the server. My understanding is that the input changes when 'onchange' event is fired (default client side event). Well, every time I type a character in the <h:inputText> element nothing happens. When <p:inputText> looses the focus nothing happens, that is, <h:outputText> isn't updated and any trace console is displayed on the console of my chrome browser. The only trace log I get is the one from my IDE console:

[TRACE] Bean:<init>():bean created
[TRACE] Bean:onPostConstruct():start
[TRACE] Bean:getText():getting text:null
[TRACE] Bean:getText():getting text:null

我不知道我在做什么错,我在想什么. 任何帮助将不胜感激.

I don't know what I'm doing wrong, what I'm missing. Any help would be pretty appreciated.

推荐答案

我已经解决了这个问题.有两个问题.第一个(不太严重的)是js回调被错误地调用.调用它们的正确方法应该如下:

I've just sorted the problem out. There were 2 problems. The first one (the less serious one) is that the js callbacks are being invoked wrong. The right way to invoke them should be as follows:

<p:ajax process="@form" update="output" onstart="onStart()" oncomplete="onComplete()" onsuccess="onSuccess()" onerror="onError()" />

严重的问题与liferay-portlet.xml配置文件中缺少参数有关. 好吧,也许我应该开始说我正在处理一个Liferay Portlet,其中包含一个使用Primefaces的JSF Portlet.这都意味着需要liferay-portlet.xml配置文件.并且此配置文件必须包含以下参数:

The serious problem is related to a missing parameter in the liferay-portlet.xml config file. Well, it maybe I should haved started saying that I was dealing with a Liferay portlet containing a JSF portlet which uses Primefaces. It all implies that liferay-portlet.xml config file is required. And this config file has to contain the following parameter:

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

问题是默认的liferay-portlet.xml文件(即eclipse IDE向导创建的文件)不会自动包含这样的参数.包含这样的参数后,一切都将按预期工作.

The problem is that the default liferay-portlet.xml file, that is, the one that the eclipse IDE wizard creates DOES NOT automatically include such a parameter. After including such a parameter, it all works as expected.

(对在Liferay Faces Bridge项目中工作的Liferay人员投反对票).

(Down vote for Liferay people working in the Liferay Faces Bridge project).

更新:我创建Liferay插件项目的方式.

  1. 新建>项目> Liferay插件项目

  1. New > Project > Liferay Plugin Project

插件类型:portlet

Plugin Type: portlet

包含示例代码->未选中

Include Sample code -> unchecked

在创建项目后启动新的Portlet向导->已选中

Launch New Portlet Wizard afer project is created -> checked

下一步> JSF 2.x

Next > JSF 2.x

显示向导时的步骤:

  1. Portlet类:javax.portlet.faces.GenericFacesPortlet
  2. 下一个 查看模板:Primefaces
  3. 下一个
  4. 完成
  1. Portlet class: javax.portlet.faces.GenericFacesPortlet
  2. Next View template: Primefaces
  3. Next
  4. Finish

这些步骤之后的主要结果是文件liferay-portlet.xml没有元素:

Major result after those steps is that file liferay-portlet.xml doesn't have the element:

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

开发设置:

  • 针对Web开发人员的Eclipse Java EE IDE 版本:Mars.2发行版(4.5.2)-内部版本号:20160218-0600
  • Liferay IDE 2.2.4.201507230603-ga5
  • Eclipse Java EE IDE for Web Developers Version: Mars.2 Release (4.5.2) - Build id: 20160218-0600
  • Liferay IDE 2.2.4.201507230603-ga5

任何澄清将不胜感激.

这篇关于p:ajax功能在Liferay门户中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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