2 Replies Latest reply on Apr 23, 2014 2:15 AM by elda

    Composite component rich:column

    elda

      Hello everyone,

       

      has anyone managed to create a composite component for a rich:column working inside a rich:extendedDataTable? My meager efforts didn't yield any results so I will probably just create a facelets tag or a fragment to be inserted. The only way I currently see to get it to work would be to override methods of the ExtendedDataTableRenderer to also check for composite component and change a few lines to actually get the correct column "sub" element of the composite component. However, I don't feel confident enough to do it that way at the moment. Not even considering the drawbacks for version changes of RichFaces in the application.

      Here is an example of what I was trying to accomplish:

      tech:richColumn:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html
          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:rich="http://richfaces.org/rich"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:c="http://java.sun.com/jstl/core"
          xmlns:cc="http://java.sun.com/jsf/composite"
          xmlns:tech="http://java.sun.com/jsf/composite/custom/technical">
      <cc:interface componentType="org.richfaces.Column">
          <cc:attribute
              name="id"
              required="true" />
          <cc:attribute
              name="renderColumn"
              type="java.lang.Boolean"
              default="true" />
          <cc:attribute
              name="sortable"
              type="java.lang.Boolean"
              default="false" />
          <cc:attribute
              name="styleClass"
              default="textAlignCenter" />
          <cc:attribute name="width" />
          <cc:attribute
              name="sortBy"
              default="#{cc.attrs.id}Column" />
          <cc:attribute
              name="colspan"
              default="1" />
          <cc:attribute
              name="exportIgnore"
              type="java.lang.Boolean"
              default="false" />
          <cc:attribute name="valueHeader" />
          <cc:attribute name="tooltipValue" />
      </cc:interface>
      <cc:implementation>
          <rich:column
              styleClass="#{cc.attrs.styleClass}"
              id="#{cc.attrs.id}Column"
              sortable="true"
              rendered="true"
              width="#{cc.attrs.width}"
              sortBy="#{cc.attrs.sortBy}"
              style="#{cc.attrs.style}"
              colspan="#{cc.attrs.colspan}">
              <f:attribute
                  name="exportIgnore"
                  value="#{cc.attrs.exportIgnore}" />
              <c:if test="#{not empty cc.attrs.valueHeader}">
                  <f:facet name="header">
                      <h:panelGroup>
                          <h:outputText
                              id="#{cc.attrs.id}Header"
                              value="#{cc.attrs.valueHeader}"
                              title="#{cc.attrs.tooltipValue}"
                              escape="false">
                          </h:outputText>
                      </h:panelGroup>
                  </f:facet>
              </c:if>
              <cc:insertChildren />
          </rich:column>
      </cc:implementation>
      </html>
      
      

      tech:extendedDataTable:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html
          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:rich="http://richfaces.org/rich"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:c="http://java.sun.com/jstl/core"
          xmlns:cc="http://java.sun.com/jsf/composite"
          xmlns:tech="http://java.sun.com/jsf/composite/custom/technical">
      <cc:interface>
          <cc:attribute
              name="id"
              required="true" />
          <cc:attribute
              name="ewdsTable"
              required="true" />
          <cc:attribute
              name="height"
              required="true" />
          <cc:attribute
              name="selectionMode"
              default="single" />
          <cc:attribute
              name="disableExport"
              type="java.lang.Boolean"
              default="false" />
          <cc:attribute name="csvTitle" />
          <cc:attribute name="selectionChangeAction" />
          <cc:attribute name="selectionChangeReRender" />
          <cc:attribute name="onRowClickAction" />
          <cc:attribute name="onRowClickReRender" />
          <cc:attribute
              name="containerStyleClass"
              default="fullFixedWidth" />
          <cc:attribute name="styleClass" />
          <cc:attribute name="style" />
      </cc:interface>
      <cc:implementation>
          <rich:extendedDataTable
              id="#{cc.attrs.id}Table"
              var="result"
              value="#{cc.attrs.ewdsTable.tableItems}"
              binding="#{cc.attrs.ewdsTable.dataTable}"
              rowClasses=",even"
              style="height:#{cc.attrs.height}px;#{style};"
              selectionMode="#{cc.attrs.selectionMode}"
              selection="#{cc.attrs.ewdsTable.selection}"
              tableState="#{cc.attrs.ewdsTable.tableState}"
              csvTitle="#{cc.attrs.csvTitle}"
              styleClass="#{cc.attrs.styleClass}"
              clientRows="#{cc.attrs.ewdsTable.rowsPerPage}">
              <a4j:ajax
                  execute="@this"
                  event="selectionchange"
                  listener="#{cc.attrs.ewdsTable.selectionListener}"
                  render="#{cc.attrs.selectionChangeReRender}"
                  immediate="true" />
              <cc:insertChildren />
          </rich:extendedDataTable>
          <h:panelGrid
              id="#{cc.attrs.id}ExternalFooterGrid"
              columns="2"
              styleClass="#{cc.attrs.containerStyleClass}">
              <h:panelGroup
                  id="#{cc.attrs.id}RowCountGroup"
                  styleClass="floatLeft">
                  <h:outputText
                      rendered="#{not cc.attrs.ewdsTable.listEmpty}"
                      id="#{cc.attrs.id}CurrentDisplay"
                      value="#{messages['tables.label.entriesCount']}" />
                  <tech:nbsp />
                  <h:outputText
                      rendered="#{not cc.attrs.ewdsTable.listEmpty}"
                      id="#{cc.attrs.id}ItemsCount"
                      value="#{cc.attrs.ewdsTable.rowCount}">
                      <f:converter converterId="LocalFormatNumberConverter" />
                  </h:outputText>
              </h:panelGroup>
              <tech:exportCSVButton
                  id="#{cc.attrs.id}Export"
                  styleClass="floatRight"
                  disabled="#{cc.attrs.ewdsTable.listEmpty}"
                  renderAsAjaxButton="#{!cc.attrs.disableExport}"
                  exportComponentId="#{cc.attrs.id}Table" />
          </h:panelGrid>
      </cc:implementation>
      </html>
      
      

      Using .xhtml:

             <tech:extendedDataTable
                  id="kleinsteClusterList"
                  ewdsTable="#{kleinsteClusterPM.searchResultTable}"
                  csvTitle="#{kleinsteClusterMessages['searchResult.title']}"
                  height="600">
                  <tech:richColumn
                      width="200"
                      id="wvbLocationColumn"
                      sortable="true"
                      valueHeader="blubb"
                      tooltipValue="bla">
                      <h:outputText value="#{result.wvbTO.number}" />
                      <h:outputText
                          value="#{messages['separator.minus']}"
                          styleClass="bold" />
                      <h:outputText value="#{result.wvbTO.id}" />
                  </tech:richColumn>
                  <rich:column id="blubb" sortable="false" sortBy="">
                      <f:facet name="header">
                          <h:outputText
                              id="blubbHeader"
                              value="this sucks"
                              title="a lot."
                              escape="false">
                          </h:outputText>
                      </f:facet>
                      <h:outputText value="#{result.wvbTO.unternehmensCode}" />
                  </rich:column>
              </tech:extendedDataTable>
      

       

      Any help would be appreciated. Composite components are awesome and really help to stick with DRY.

       

      Thank you and have a nice evening

      Cheers,

      Michael

       

      Message was edited by: Michael Colin: Used the wrong insert for my code snippets.

        • 1. Re: Composite component rich:column
          bleathem

          This should work.  The RichFaces datatable renderers usually check for the instance of AbstractColumn, which is the component mapped to by the componentType you are using.  What exactly is failing?

          • 2. Re: Composite component rich:column
            elda

            That's what I thought as well and if I debug the renderer it gets way further than without the componentType, but not all the way. The result is a column which will never be rendered. Even though my composite component does include a header facet, the renderer can't find that facet, for example. The same seems to happen with child components. I am not exactly sure how the "hidden" wrapper group of the composite component and the componentType interact. But could it be possible the renderer actually receives the wrapper instead of the one subcomponent rich:column and tries to render this wrapper (which would obviously not result in anything visible/usable)?

             

            edit: Custom attributes set in my rich:column (exportIgnore, for example) are not present in the component either. I'd have to check if there is a child present with my attribues and values. I'll update later when I have checked my theory.