2012-08-28 36 views
0

我是新來的primefaces,我想使用自動完成標籤的primeface.So我folllowed this example
這裏是我的代碼
Primefaces自動完成不工作,並且沒有任何異常

layout.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:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:p="http://primefaces.org/ui"> 
<head> 

<title>Title</title> 
</head> 
<body> 
<h:form id="form"> 
    <p:panel header="AutoComplete" toggleable="true" id="panel"> 
     <h:panelGrid columns="2" cellpadding="5"> 

      <h:outputLabel value="Simple :" for="acSimple" /> 
      <p:autoComplete id="acSimple" value="#{autoCompleteBean.txt1}" 
        completeMethod="#{autoCompleteBean.complete}"/> 
        </h:panelGrid> 
        </p:panel> 
        </h:form> 
</body> 
</html> 

AutoCompleteBean.java

import java.util.ArrayList; 
import java.util.List; 

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.RequestScoped; 
@ManagedBean(name="autoCompleteBean") 
@RequestScoped 
public class AutoCompleteBean { 

    private String txt1; 

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

    public String getTxt1() { 
     return txt1; 
    } 

    public void setTxt1(String txt1) { 
     this.txt1 = txt1; 
    } 
} 

所以layout.xhtml呈現罰款和向我展示的文本字段,但隨後後不工作並且不顯示自動完成功能。
有什麼缺失嗎?或者會是什麼問題
感謝

回答

1

您發佈使用標準的HTML標籤爲頭的XHTML所以它可能無法正確解釋的Javascript用來調用的完整方法豆。

嘗試使用H:頭H:身體

提示可能會顯示在您的輸出窗口中。檢查類似:

sourceId=null[severity=(ERROR 2), summary=(One or more resources have the target of 'head', but no 'head' component has been defined within the view.), detail=(One or more resources have the target of 'head', but no 'head' component has been defined within the view.)] 

參見小時堆棧溢出討論:在primefaces頭:What's the difference between <h:head> and <head> in Java Facelets?

0

你應該總是使用H:頭H:身體當你寫個小面。原因是,爲了讓自動完成工作JavaScript是必需的,如果你不包括h:head jsf將無法正確放置javascript。

0

我也有類似的問題,但是在我的情況,當我刪除一個p標籤這是圍繞P中的問題得到解決:自動完成標籤。

以下代碼不會拋出錯誤消息,但自動選擇下拉菜單不會出現。刪除<p></p>後,一切工作正常。

<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:p="http://primefaces.org/ui" 
xmlns:f="http://xmlns.jcp.org/jsf/core" 
xmlns:h="http://xmlns.jcp.org/jsf/html"> 
<h:head> 
</h:head> 
<h:body> 
    <h:form> 
     <p> 
      <p:autoComplete id="place" value="#{addPlaceBean.place}" 
       completeMethod="#{autoCompletePlace.completePlace}" var="place" 
      itemLabel="#{place.city}, #{place.country}" 
      itemValue="#{place}" converter="placeConverter"> 
      </p:autoComplete> 
     </p> 
    </h:form> 
</h:body> 
</html> 
+0

你真的,真的嗎?我無法想象這一點。 p標籤上沒有任何css引起問題嗎? – Kukeltje

+0

我現在用一個最小的例子(見上面)嘗試它,問題仍然是一樣的。 – Nik