4

我正在尝试 自动完成演示。我没有收到任何错误,但 httprequest/response 显示它正在与服务器通信,而不是与 bean 通信。我正在使用最新版本的 primefaces 3.4。

任何帮助表示赞赏。

豆 :

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import com.zreflect.emyed.managedbean.BaseMB;

@ManagedBean
@ViewScoped
public class CircleSearchBean extends BaseMB implements Serializable {
    private static final long serialVersionUID = 1L;
    private String selected;
    List<String> results = new ArrayList<String>();
    public List<String> complete(String query) {
        List<String> results = new ArrayList<String>();
        for (int i = 0; i < 10; i++) {
            results.add(query + i);
        }
        return results;
    }
    /**
     * @return the selected
     */
    public String getSelected() {
        return selected;
    }

    /**
     * @param selected
     *            the selected to set
     */
    public void setSelected(String selected) {
        this.selected = selected;
    }
}

XHTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
    <title><h:outputText value="test" /></title>
</h:head>

<h:body>
<h:form>
<p:autoComplete value="#{circleSearchBean.selected}" completeMethod="#{circleSearchBean.complete}"/> 
</h:form>
</h:body>
</html>

这是来自 Chrome 开发者工具的调试信息。

要求:

Request URL:http://localhost:8080/PrimefacesTest/faces/index.xhtml
Request Method:POST
Status Code:200 OK

请求标头:

Accept:application/xml, text/xml, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:157
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:JSESSIONID=60Wd6aXSj6rDbPOgvMCoFJFF.undefined
Faces-Request:partial/ajax
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/PrimefacesTest/faces/index.xhtml
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
X-Requested-With:XMLHttpRequest

表格数据:

javax.faces.partial.ajax:true
javax.faces.source:j_idt8
javax.faces.partial.execute:j_idt8
javax.faces.partial.render:j_idt8
j_idt8:j_idt8
j_idt8_query:hello

响应标头:

Cache-Control:no-cache
Content-Length:346
Content-Type:text/xml;charset=UTF-8
Date:Sun, 02 Sep 2012 21:11:42 GMT
Server:Apache-Coyote/1.1
X-Powered-By:JSF/2.0
4

1 回答 1

2

在将“id”属性添加到自动完成后,它现在正在工作,如演示中所示。

<p:autoComplete id="autocomplete" value="#{circleSearchBean.selected}" 
   completeMethod="#{circleSearchBean.complete}"/>  

在一个单独的项目中,它在没有“id”属性的情况下工作。看起来像一个错误。

于 2012-09-03T18:40:53.767 回答