p:ajax feature not working in Liferay portal

微笑、不失礼 提交于 2019-12-01 13:07:42

问题


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 side

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

Bean side:

@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 side:

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

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

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

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

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.


回答1:


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()" />

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>

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.

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

UPDATE: The way I create the Liferay Plugin Project.

  1. New > Project > Liferay Plugin Project

    Plugin Type: portlet

    Include Sample code -> unchecked

    Launch New Portlet Wizard afer project is created -> checked

  2. Next > JSF 2.x

  3. Next > Primefaces
  4. Finish

Steps when Wizard is displayed:

  1. Portlet class: javax.portlet.faces.GenericFacesPortlet
  2. Next View template: Primefaces
  3. Next
  4. Finish

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

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

Development settings:

  • 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

Any clarification would be appreciated.



来源:https://stackoverflow.com/questions/46196412/pajax-feature-not-working-in-liferay-portal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!