-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");

mabi
  • 5,279
  • 2
  • 43
  • 78
vmaric
  • 369
  • 1
  • 4
  • 14
  • I don't quite get what you have problems with. `ui:composition` is the start tag, it never takes "parameters". If you're wondering how your composite component will be named, that's the name of the file you put this code in. – mabi Jul 30 '13 at 11:20

1 Answers1

0

For the first question: <ui:composition template="..."> renders the content's of this tag into the specified template. Since you have no template here, the attribute isn't needed.

For the second question: findComponent searches for the given id in the enclosing NamingContainer, which is your composite component (check the Javadoc for the full algorithm). It's not like jQuery where it only searches "below" the given component.

mabi
  • 5,279
  • 2
  • 43
  • 78
  • Is every component on some page are one Naming Container – vmaric Jul 30 '13 at 12:42
  • Each use of the composite component creates a new naming container, yes. – mabi Jul 30 '13 at 12:52
  • Thanks a lot. Because we have in the back end ... and on min page it is presented like one composite component with own attribute, that is a reason way we have – vmaric Jul 30 '13 at 12:57
  • I'm sorry, I don't understand your problem. Can you restate? For more information about NamingContainers see the excellent answer by BalusC in http://stackoverflow.com/a/8644762/785663 – mabi Jul 30 '13 at 13:08
  • You already answered my questions. And thank a lot for good link. Actually I`m not understand the concept of naming containers! – vmaric Jul 31 '13 at 06:56
  • Bath now every thing will be ok! – vmaric Jul 31 '13 at 07:03