-1

A have found sample on internet(IBM site http://www.ibm.com/developerworks/web/library/j-jsf2fu-0410/index.html#listing1) and on some book that with JSF can make auto complete drop down list. Like on google search page. The main point of this is in using composite component page. It look like:

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

My questions are:

  1. Why we use ui:composition tags with out any parameters.

  2. We have in h:inputText defined valueChangeListener, realized over backend class which has method public void valueChanged(ValueChangeEvent e) with these two lines

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

    If (UIInput)e.get source return component inputText with id="name". How possible next line UISelectOne listbox = (UISelectOne)input.findComponent("listbox");

4

1 回答 1

0

对于第一个问题:<ui:composition template="...">将此标签的内容呈现到指定的模板中。由于此处没有模板,因此不需要该属性。

对于第二个问题:findComponent在封闭的 id 中搜索给定的 id NamingContainer,这是您的复合组件(检查Javadoc以获取完整算法)。它不像 jQuery,它只在给定组件的“下方”搜索。

于 2013-07-30T12:04:51.487 回答