【问题标题】:Primefaces 3.5 AutoComplete not working with Liferay 6.1 GA2Primefaces 3.5 AutoComplete 不适用于 Liferay 6.1 GA2
【发布时间】:2013-09-20 05:57:18
【问题描述】:

我正在使用 Liferay 6.1 GA2 和 JSF 2.0(liferay 面向 3.1.2-ga3mojarra 2.1.21 >primefaces 3.5)。我正在尝试实现一个自动完成字段(多个),但它不起作用。没有调用 backing bean 中的完整方法。

但是,如果我使用带有下拉列表的单个简单自动完成字段,则我的 bean 中的完整方法会在按钮单击时调用,并将一个空查询传递给该方法。

我的代码如下:

content.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<f:view xmlns="http://www.w3.org/1999/xhtml"
    xmlns:aui="http://liferay.com/faces/aui"
    xmlns:aui-cc="http://liferay.com/faces/aui-cc"
    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:portlet="http://java.sun.com/portlet_2_0"
    xmlns:bridge="http://portletfaces.org/bridge"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core"

    version="2.1">

    <ui:composition template="template.xhtml">
        <ui:define name="content-placeholder">
            <div class="tab_main_content">
                <aui:layout>
                        <p:autoComplete id="to" name="to" value="#{myBean.to}" completeMethod="#{myBean.getUsers}" multiple="true"/> 
                </aui:layout>
            </div>
        </ui:define>
    </ui:composition>
</f:view>

template.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<f:view xmlns="http://www.w3.org/1999/xhtml"
    xmlns:aui="http://liferay.com/faces/aui"
    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:portlet="http://java.sun.com/portlet_2_0"
    xmlns:liferay-ui="http://liferay.com/faces/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core"

    version="2.1">

    <div id="msgPortletDiv" class="gray_box3">
        <h:form method="post" enctype="multipart/form-data">
            <!-- INSERT: For content -->
            <ui:insert name="content-placeholder">
                    placeholder text
            </ui:insert>
        </h:form>
    </div>  
</f:view>

来自支持 bean (getUsers) 和 'to' 属性的完整方法

private List<String> to = new ArrayList<String>();

// Autocomplete method
public List<String> getUsers(String query) {  
    _log.info("getUsers() method in myBean for query: " + query);
    List<String> results = new ArrayList<String>(); 

    return results;  
}  

//Getter and setter for 'to'
public List<String> getTo() {
    return to;
}

public void setTo(List<String> to) {
    this.to = to;
}

我不确定是否存在兼容性问题,或者我只是做错了什么。我似乎无法在网上找到 primefaces 的 autoComplete with liferay 的任何演示。

任何帮助将不胜感激!

** EDIT:为了排除故障,我尝试简化我的 content.xhtml 并且不使用 template.xhtml,但它仍然没有触发 backing bean 方法。如前所述,简单的下拉版本 onclick 适用于此,但不适用于非下拉自动完成字段的 ajax 调用。

简化内容.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<f:view xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"

    version="2.1">
    <h:form>
        <div class="tab_main_content message-body">
            <p:autoComplete id="to" name="to" value="#{myBean.to}" completeMethod="#{myBean.getUsers}" multiple="true"/>
        </div>
    </h:form>
</f:view>

【问题讨论】:

  • 如果你删除 会起作用吗?
  • 不幸的是它没有...我已经更改了 content.xhtml 中的代码以删除对 template.xhtml 和 aui:layout 的使用,但它仍然不会触发支持 bean 方法。

标签: jsf-2 primefaces autocomplete liferay-6


【解决方案1】:

我认为一切都差不多。但是您需要在 backing bean 中更改一件事。你说下拉效果很好。所以选择 1 个用户是没有问题的。如果在您的支持 bean 中 #{myBean.to} 被定义为 private User to 这适用于一个选择,因为它可以容纳 1 个用户实例。

如果您将其更改为 private List&lt;User&gt; to 您可以在列表中保存多个用户实例。不要忘记添加 getter 和 setter,一切顺利

【讨论】:

  • 我的 backing bean 中确实有 getter 和 setter(抱歉,我之前没有包含它们)。我现在已经在我的问题中包含了该代码。为了澄清起见,对于单个选择,如果我不使用 dropdown="true",它也不起作用。似乎是文本框 onchange ajax 调用有问题。仅当我手动单击下拉按钮时,对支持 bean 完成方法的调用才有效。
  • 如果你用 firebug 调试请求,你会看到什么?
  • 天哪,我早该这么做了!打开 firebug 并使用它(我之前使用的是 chrome,这不是很有帮助)后,我收到了这个错误:TypeError: $.ui is undefined。我包含了 jquery-ui js,现在触发了完整的方法。非常感谢您推动我朝着正确的方向前进!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
  • 2013-05-17
  • 2017-11-29
  • 1970-01-01
  • 2014-08-27
相关资源
最近更新 更多