Jsf 2 自动编译自定义组件如何工作?

Jsf 2 自动编译自定义组件如何工作?,jsf-2,Jsf 2,我们在internet(IBM站点)和一些书籍上找到了一个示例,使用JSF可以自动生成完整的下拉列表。比如谷歌搜索页面。其要点在于使用复合组件页面。它看起来像: <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://ja

我们在internet(IBM站点)和一些书籍上找到了一个示例,使用JSF可以自动生成完整的下拉列表。比如谷歌搜索页面。其要点在于使用复合组件页面。它看起来像:

<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>
如果(UIInput)e.使用id=“name”获取源返回组件inputText。下一行怎么可能 UISelectOne列表框=(UISelectOne)input.findComponent(“列表框”)


对于第一个问题:
将此标记的内容呈现到指定的模板中。因为这里没有模板,所以不需要该属性


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

我不太明白您有什么问题
ui:composition
是开始标记,它从不接受“参数”。如果您想知道复合组件将如何命名,这就是您将此代码放入的文件的名称。可以是某个页面上的每个组件都是一个命名容器。每次使用复合组件都会创建一个新的命名容器,是的。非常感谢。因为我们在后端有。。。在min页面上,它像一个具有自己属性的复合组件一样呈现,这就是我们采用这种方式的原因。对不起,我不理解您的问题。你能再说一遍吗?有关NamingContainers的更多信息,请参阅BalusC在《你已经回答了我的问题》中的精彩答案。非常感谢你们的链接。实际上,我不理解命名容器的概念!
UIInput input = (UIInput) e.getSource();
UISelectOne listbox = (UISelectOne) input.findComponent("listbox");