1 Reply Latest reply on Nov 5, 2010 10:33 AM by nbelaevski

    Scope of RichFaces built-in client functions

    noxhoej

      Hi

       

      Is there any reason, why the RichFaces built-in client functions (See Chapter 14. Functions), like rich:clientId('id') doesn't find the "closest" element with the given id, instead of searching from the root naming container, returning the first element with the given id? Or is there another way to access the needed "closest" element? It seems that most other things, resolve ids by starting at the closest NamingContainer, moving upwards by parent NamingContainers, searching for the relevant id in each NamingContainer until finally arriving at the root.

       

      If, for example, I have a composition template test.xhtml:

       

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:rich="http://richfaces.org/rich"
                      xmlns:s="http://jboss.com/products/seam/taglib">
          <s:div id="mydiv">
              <ui:insert/>
          </s:div>
          Div ID: #{rich:clientId('mydiv')}
          <script type="text/javascript">
              #{rich:element('mydiv')}.style.background='red'
          </script>
      </ui:composition>

       

      which I use to decorate some example text:

       

      <s:decorate template="test.xhtml">
        Text1
      </s:decorate>
      <s:decorate template="test.xhtml">
        Text2
      </s:decorate>

       

      I would expect the output to look like

       

      expected.gif

       

      but instead it renders as

       

      actual.gif

       

      because both functions find the first div on the page with an id of "mydiv", instead of the "closest" (i.e. in the same NamingContainer).

        • 1. Re: Scope of RichFaces built-in client functions
          nbelaevski

          Hi Nicholas,

           

          JSF 1.2 didn't provide current component context, that's why the search is done always from UIViewRoot. In RF 4/JSF 2.0 this is changed and the search is done starting from the current component. As a workaround you can qualify id with several more segments, like: container:myDiv.