7 Replies Latest reply on Oct 18, 2010 3:37 AM by henryju

    How to wrap rich:column in a facelet tag

    henryju

      Hi,

       

      I would like to create a custom facelet tag to add features to the existing rich:column tag.

       

      I have created the following file:

       

      column.xhtml

      {code:xml}

      <ui:composition xmlns:f="http://java.sun.com/jsf/core" xmlns:rich="http://richfaces.org/rich" xmlns:ui="http://java.sun.com/jsf/facelets">

          <rich:column id="#{id}" filterBy="#{filterBy}">

              <f:facet name="header">

                  <h:outputText styleClass="headerText" value="#{header}" />

              </f:facet>

              <ui:insert/>

          </rich:column>

      </ui:composition>

      {code}

       

      then I use it this way:

       

       

      {code:xml}

      <rich:table var="person" ...>

         <my:column id="col1" header="Name" filterBy="#{person.name}">#{person.name}</my:column>

         <my:column id="col2" header="Age">#{person.age}</my:column>

      </rich:table>

      {code}

       

      The problem is the filter input field is displayed for the two columns even if I don't specify filterBy attribute.

       

      How can I set the filterBy attribute on rich:column only when it is also defined on the my:column tag?

       

      Thanks

        • 1. Re: How to wrap rich:column in a facelet tag
          nbelaevski

          Hi Julien,

           

          When column makes decision on whether filtering input is being rendered or not, it checks for the presence of "filterBy" value expression. But in your template it's always set, so you see the input (when Facelet templates are processed, new instances of VariableMapper pointing to tag expressions are created). So, as a workaround you can try creating TagHandler that will handle that - check Facelets API for details.

          1 of 1 people found this helpful
          • 2. Re: How to wrap rich:column in a facelet tag
            henryju

            Hi Nick,

             

            First thanks for your reply.

             

            If I understand correctly you are suggesting to not use a xhtml template to create a custom tag but instead use a Java TagHandler (extending rich:column tag handler?). My concern is about WYSIWYG feature in Eclipse. I read that using xhtml template doesn't prevent VPE to display a preview of the page (I have not checked this point yet). But if I choose to use custom TagHandler I guess I will loose the ability to have a preview of my page.

             

            Any suggestion?

             

            Regards,

             

            Julien

            • 3. Re: How to wrap rich:column in a facelet tag
              nbelaevski

              Julien,

               

              In this case tag with custom tag handler will be wrapping included page content, so it will probably work.

              • 4. Re: How to wrap rich:column in a facelet tag
                ilya_shaikovsky

                as just simple alternative - you could create different  facelets for simple columns and ones without filtering

                • 5. Re: How to wrap rich:column in a facelet tag
                  henryju

                  Ilya Shaikovsky wrote:

                   

                  as just simple alternative - you could create different  facelets for simple columns and ones without filtering

                  Yeah, that's what is done currently and I want to refactor:

                  <my:columnWithFilter>

                  <my:columnWithSort>

                  <my:columnSimple>

                  <my:columnWithFilterAndSort>

                  ...

                  Ugly isn't it

                  • 6. Re: How to wrap rich:column in a facelet tag
                    ahoehma

                    Try this:

                     

                    <ui:composition xmlns:f="http://java.sun.com/jsf/core" 
                                    xmlns:rich="http://richfaces.org/rich"
                                    xmlns:ui="http://java.sun.com/jsf/facelets"
                                    xmlns:c="http://java.sun.com/jstl/core">

                      <c:if test="#{!empty filterBy}">
                        <rich:column id="#{id}" filterBy="#{filterBy}">       <f:facet name="header">         <h:outputText styleClass="headerText" value="#{header}" />       </f:facet>       <ui:insert/>     </rich:column>
                      </c:if>


                     
                    <c:if test="#{empty filterBy}">
                        <rich:column id="#{id}">       <f:facet name="header">         <h:outputText styleClass="headerText" value="#{header}" />       </f:facet>       <ui:insert/>     </rich:column>
                      </c:if>

                    </ui:composition>

                     

                    Regards

                    Andreas

                    -=[http://www.ahoehma.de]=-

                    1 of 1 people found this helpful
                    • 7. Re: How to wrap rich:column in a facelet tag
                      henryju

                      With optional filtering and optional sorting it leads to at least 4 combinations. I wanted to avoid duplicate code but it seems this is the only solution...

                       

                      Thanks