Sudipta Deb
Sudipta Deb

Reputation: 1050

PrimeFaces dataTable Composite Component Default Value

I have the below composite component

<ui:component xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:cc="http://java.sun.com/jsf/composite"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:p="http://primefaces.org/ui">

    <cc:interface>
        <cc:attribute name="rows" />
        <cc:attribute name="value"
            type="org.primefaces.model.LazyDataModel" />
        <cc:attribute name="var" />
        <cc:attribute name="id" />
        <cc:attribute name="rowStyle" default="false"/>
    </cc:interface>

    <cc:implementation>
        <p:dataTable value="#{cc.attrs.value}"
            rendered="#{not empty cc.attrs.value}" id="#{cc.attrs.id}"
            paginator="true" rows="25" 
            currentPageReportTemplate="Showing {startRecord}-{endRecord} of {totalRecords}"
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="25,50,100" paginatorPosition="bottom"
            lazy="true" rowStyleClass="#{cc.attrs.rowStyle}">
             <c:set target="#{component}" property="var" value="#{cc.attrs.var}"/>
            <cc:insertChildren />
        </p:dataTable>
    </cc:implementation>
</ui:component> 

My requirement is: In few cases, I will pass the value of rowStyle otherwise if the value is not passed, it should take the default value.

I have the added the below line in my composite component

<cc:attribute name="rowStyle" default="false"/>

But it is not working. Why?

Upvotes: 0

Views: 1644

Answers (2)

Devon_C_Miller
Devon_C_Miller

Reputation: 16528

Keep in mind that the default attribute is for handling the case where the attribute is not passed, not the case where the attribute is null.

So, given this interface:

<cc:interface>
    <cc:attribute name="monkey" />
    <cc:attribute name="food" default="banana" />
</cc:interface>

If I invoke it like this, the value of food will be banana:

<barrel monkey="Bonzo" />

However, if myFood is null and I invoke it like this:

<barrel monkey="Bonzo" food="#{myFood}" />

Then the value of food will be null.

Upvotes: 2

Kjiro
Kjiro

Reputation: 49

I think that you need to enter acctual CSS class name into the default.

So, the default value is not true/false flag, but field with actual value.

Upvotes: 0

Related Questions