2013-07-30 17 views
0

A在互聯網上找到了樣本(IBM站點http://www.ibm.com/developerworks/web/library/j-jsf2fu-0410/index.html#listing1),並且在某些書上使用JSF可以使自動完成下拉列表。喜歡在谷歌搜索頁面。這個主要點在使用複合組件頁面。它看起來像:如何工作自動complite自定義組件?

<ui:composition 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:composite="http://java.sun.com/jsf/composite"> 

    <!-- INTERFACE --> 
    <composite:interface> 
     <composite:attribute name="value" required="true"/> 
     <composite:attribute name="completionItems" required="true"/> 
    </composite:interface> 

    <!-- IMPLEMENATION -->   
    <composite:implementation> 
     <div id="#{cc.clientId}"> 
     <h:outputScript library="javascript" 
      name="prototype-1.6.0.2.js" target="head"/> 

     <h:outputScript library="javascript" 
      name="autoComplete.js" target="head"/> 

     <h:inputText id="input" value="#{cc.attrs.value}" 
      onkeyup="com.corejsf.updateCompletionItems(this, event)" 
      onblur="com.corejsf.inputLostFocus(this)" 
      valueChangeListener="#{autocompleteListener.valueChanged}"/> 

     <h:selectOneListbox id="listbox" style="display: none" 
      valueChangeListener="#{autocompleteListener.completionItemSelected}"> 

      <f:selectItems value="#{cc.attrs.completionItems}"/> 
      <f:ajax render="input"/> 

     </h:selectOneListbox> 
     <div> 
    </composite:implementation>  
</ui:composition> 

我的問題是:

  1. 爲什麼我們使用的用戶界面:成分標籤與任何參數。

  2. 我們在H:inputText的定義valueChangeListener,實現在其上具有方法public void valueChanged(ValueChangeEvent e)與這兩條線後端類

    UIInput input = (UIInput) e.getSource(); 
    UISelectOne listbox = (UISelectOne) input.findComponent("listbox"); 
    

    如果(UIInput)e.get源返回部件的inputText使用id = 「名稱」 。如何可能下一行 UISelectOne listbox =(UISelectOne)input.findComponent(「listbox」);

+0

我不太明白你有什麼問題。 'ui:composition'是開始標記,它從不需要「參數」。如果您想知道如何命名複合組件,那麼您將此代碼放在該文件的名稱中。 – mabi

+0

可以是 vmaric

回答

0

對於第一個問題:<ui:composition template="...">呈現此標記的內容到指定的模板。由於此處沒有模板,因此不需要該屬性。

對於第二個問題:findComponent搜索包含NamingContainer(這是您的複合組件)(對於完整算法,請檢查the Javadoc)中給定的id。它不像jQuery,它只在給定組件的「下方」搜索。

+0

某個頁面上的每個組件都是一個命名容器 – vmaric

+0

複合組件的每次使用都會創建一個新的命名容器,是的。 – mabi

+0

非常感謝。因爲我們已經在後端 ...並且在最小頁面上呈現爲具有自己屬性的一個複合組件,這是我們擁有 vmaric