Ignacio
Ignacio

Reputation: 121

Reuse Component JSF2.1 with Facelets

im using:

I have a Table that i want to reuse as datable or subtable depends of the page that i use the component, i want to put and if but it doesnt work, here is my code:

<!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:h="http://java.sun.com/jsf/html"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:o="http://omnifaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:composite="http://java.sun.com/jsf/composite"
      xmlns:tablas="http://java.sun.com/jsf/composite/tablas"
      >

    <!-- INTERFACE -->
    <composite:interface>
        <composite:attribute name="listaPaqueteItems" required="true" />
        <composite:attribute name="subtable" required="false" default="false" />
    </composite:interface>

    <!-- IMPLEMENTATION -->
    <composite:implementation>


        <c:if test="#{!cc.attrs.subtable}"> 
            <rich:dataTable id="tabla_items_del_paquete"
                value="#{cc.attrs.listaPaqueteItems}"
                var="p"
                rowKeyVar="row_tabla_items_del_paquete"
                rows="10"
                rowClasses="odd-row, even-row"
                styleClass="stable">
        </c:if> 
        <c:if test="#{cc.attrs.subtable}">  
            <rich:collapsibleSubTable id="subtable">
        </c:if>
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="#" />
                    </f:facet>
                    <h:outputText value="#{row_tabla_items_del_paquete + 1}" />
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="#{msgs['abm.paquete.item.tabla.codigo']}" />
                    </f:facet>
                    <h:outputText value="#{p.producto.codigo}" />
                </rich:column>                  
                <rich:column colspan="2">
                    <f:facet name="header">
                        <h:outputText value="#{msgs['abm.paquete.item.tabla.nombre']}" />
                    </f:facet>
                    <b>
                        <h:outputText value="#{p.producto.nombre}" />
                    </b>
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="#{msgs['abm.paquete.item.tabla.descuento.final']}" />
                    </f:facet>
                    <h:outputText value="#{p.descuentoFinal}" />
                </rich:column>                  

        <c:if test="#{!cc.attrs.subtable}"> 
            </rich:dataTable> 
        </c:if> 
        <c:if test="#{cc.attrs.subtable}">  
            </rich:collapsibleSubTable> 
        </c:if>
    </composite:implementation>    

</html>

Basically the problem is that isnt valid XHTML, any idea to accomplish this scenario and try to reuse this code as table or subtable, one possible idea is externally the <rich:colum> tags in another template and wrapper that in datable or subtable something like this:

            <rich:collapsibleSubTable
            expanded="#{false}"
            id="tabla_periodos"
            rowKeyVar="row_subtable"
            expandMode="client"
            value="#{p.periodoDescuentos}"
            var="per"
            rendered="#{not empty p.periodoDescuentos}"
            >
<!-- Include Columns-->
                </rich:collapsibleSubTable>

I think that will work but maybe is another way to do the same better.

Upvotes: 0

Views: 214

Answers (1)

skybber
skybber

Reputation: 409

You can create facelet tag with following code:

TAG (myTable.xhtml):

     <c:if test="#{!subtable}"> 
        <rich:dataTable id="tabla_items_del_paquete"
            value="#{listaPaqueteItems}"
            var="p"
            rowKeyVar="row_tabla_items_del_paquete"
            rows="10"
            rowClasses="odd-row, even-row"
            styleClass="stable">
           <ui:insert>
         </rich:dataTable>
    </c:if> 
    <c:if test="#{subtable}">  
        <rich:collapsibleSubTable id="subtable">
           <ui:insert>
        </rich:collapsibleSubTable>
    </c:if>

USAGE:

    <my:mytable>
       ... your dataTable content
    </my:mytable>

Upvotes: 2

Related Questions