3 Replies Latest reply on Oct 26, 2009 12:18 AM by Tim Evers

    Facelets - Custom Component

    Ralf H. Newbie

      Hi Guys,


      this is no Seam specific question. I need some help regarding a custom component.


      I want to use a component surrounded by some html tags etc... , which i dont want to rewrite every time. So i decided to create a custom component.


      I created a taglib:



      <?xml version="1.0"?>
      <!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd">
      <facelet-taglib>
          <namespace>http://www.neologics.de/jsf/</namespace>
          <tag>
            <tag-name>field</tag-name>
            <source>components/buttons/button.xhtml</source>
          </tag>
      </facelet-taglib>
      



      imported the taglib into the web.xml:


      <context-param>
        <param-name>facelets.LIBRARIES</param-name>
        <param-value>/WEB-INF/neologics.taglib.xml</param-value>
      </context-param>






      I created a template:



      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:h="http://java.sun.com/jsf/html"
                      xmlns:f="http://java.sun.com/jsf/core"
                      xmlns:s="http://jboss.com/products/seam/taglib"
                      xmlns:rich="http://richfaces.org/rich"
                      xmlns:a4j="http://richfaces.org/a4j"
              >
      
          <div class="view-quicksearch-button">
            <span class="genericButton genericButtonBig">
              <span class="t" />
              <span class="cl">
                <span class="cr">
                  <span class="c">
                      insert some content here
                  </span>
                </span>
              </span>
              <span class="b" />
              <span class="tl" />
              <span class="tr" />
              <span class="br" />
              <span class="bl" />
            </span>
          </div>
      </ui:composition>




      and used the component in this way:


      <n:field title="auswählen" >
        <rich:spacer />
      </n:field>
      



      What do i have to change, that the eg. rich:spacer is visible in the insert some content here in the component???


      Thanks in advance,


      Ralf

        • 1. Re: Facelets - Custom Component
          Arbi Sookazian Master

          Can't you add it directly in the template you created?  What exactly will the spacer do in this case? (you don't specify height or width).  Just insert a new line?

          • 2. Re: Facelets - Custom Component
            Ralf H. Newbie

            yes, i could ... but i want to inject other components like h:commandbuttons...

            • 3. Re: Facelets - Custom Component
              Tim Evers Master

              Ok, for starters the answer to your question is very very easy. But, before just following what I show you, you really should take the time to read this web page as it will help you so very much with understanding how to do much more complicated things in the future.


              http://www.ibm.com/developerworks/java/library/j-facelets/


              Now, to fix your problem, where you have put insert some content here just replace that with


              <ui:insert />
              



              Now, it will work exactly how you want.




              It should look like:


              <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                              xmlns:ui="http://java.sun.com/jsf/facelets"
                              xmlns:h="http://java.sun.com/jsf/html"
                              xmlns:f="http://java.sun.com/jsf/core"
                              xmlns:s="http://jboss.com/products/seam/taglib"
                              xmlns:rich="http://richfaces.org/rich"
                              xmlns:a4j="http://richfaces.org/a4j"
                      >
              
                  <div class="view-quicksearch-button">
                    <span class="genericButton genericButtonBig">
                      <span class="t" />
                      <span class="cl">
                        <span class="cr">
                          <span class="c">
                              <ui:insert />
                          </span>
                        </span>
                      </span>
                      <span class="b" />
                      <span class="tl" />
                      <span class="tr" />
                      <span class="br" />
                      <span class="bl" />
                    </span>
                  </div>
              </ui:composition>