Jsf PrimeFaces数据表复合组件默认值
我有下面的复合组件Jsf PrimeFaces数据表复合组件默认值,jsf,jsf-2,primefaces,datatable,composite-component,Jsf,Jsf 2,Primefaces,Datatable,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"
<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>
我的要求是:
在少数情况下,我将传递rowStyle的值,否则如果未传递该值,则应采用默认值
我已经在我的复合组件中添加了以下行
<cc:attribute name="rowStyle" default="false"/>
但它不起作用。为什么?我认为您需要在默认值中输入实际的CSS类名
因此,默认值不是真/假标志,而是带有实际值的字段。请记住,
default
属性用于处理属性未通过的情况,而不是属性为空的情况
因此,考虑到这个接口:
<cc:interface>
<cc:attribute name="monkey" />
<cc:attribute name="food" default="banana" />
</cc:interface>
但是,如果myFood
为null
并且我这样调用它:
<barrel monkey="Bonzo" food="#{myFood}" />
然后food
的值将为null
<barrel monkey="Bonzo" food="#{myFood}" />