tags:

views:

185

answers:

1

I have a base datatable with 20 columns which is used by all reports...Some reports add additional columns, is there a way to put the code for the extra column in a separate JSF page and reference this some how?

e.g.

datatable.jsp

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<h:dataTable value="#{table}" var="item" styleClass="report-table">
    <f:subview id="tb1">
        <jsp:include page="/jsp/include.jsp" />
    </f:subview>
</h:dataTable>


include.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>


<t:column >
        <f:facet name="header">
                <h:outputText value="User" />
        </f:facet>
        <h:outputText value="MyUser"></h:outputText>
</t:column>
+1  A: 

No it is not possible. Your best bet is the rendered attribute of the h:column component. If it evaluates to true, then the column in question will be displayed. E.g.:

<h:dataTable value="#{bean.list}" var="item">
    <h:column>
        This is always displayed.
    </h:column>
    <h:column rendered="#{bean.additionalColumnRequired}">
        This is only displayed when additionalColumnRequired == true.
    </h:column>
    <h:column rendered="#{!bean.additionalColumnRequired}">
        This is only displayed when additionalColumnRequired == false.
    </h:column>
</h:dataTable>

.. where the boolean getter look like this:

public boolean isAdditionalColumnRequired() {
    return ... // true or false.
}

You can however put any kind of boolean expression in the rendered attribute.

<h:someComponent rendered="#{bean.booleanValue}" />
<h:someComponent rendered="#{bean.intValue > 10}" />
<h:someComponent rendered="#{bean.objectValue == null}" />
<h:someComponent rendered="#{bean.stringValue != 'someValue'}" />
<h:someComponent rendered="#{!empty bean.collectionValue}" />
<h:someComponent rendered="#{!bean.booleanValue && bean.intValue != 0}" />
<h:someComponent rendered="#{bean.stringValue == 'oneValue' || bean.stringValue == 'anotherValue'}" />
BalusC