我有下面的复合组件
<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"/>但它不起作用。为什么?
发布于 2015-10-15 21:52:15
请记住,default属性用于处理属性为的情况,而不是属性为空的情况。
因此,给定此接口:
<cc:interface>
<cc:attribute name="monkey" />
<cc:attribute name="food" default="banana" />
</cc:interface>如果我像这样调用它,food的值将是banana
<barrel monkey="Bonzo" />但是,如果myFood为null,并且我像这样调用它:
<barrel monkey="Bonzo" food="#{myFood}" />则food的值将为null。
发布于 2013-12-13 23:41:33
我认为您需要在默认设置中输入实际的CSS类名。
因此,默认值不是true/false标志,而是具有实际值的字段。
https://stackoverflow.com/questions/19721786
复制相似问题