tags:

views:

35

answers:

2

if there is no data to display, jsf data table shows headers only. How to say that no records available and also tell me is there any way to get the row index with out having a specific method. thanks in advance

. .

+1  A: 

You can make use of the rendered attribute of the component in question to set whether to render it in the component tree or not. E.g.

<h:dataTable value="#{bean.data}" rendered="#{not empty bean.data}">
    ...
</h:dataTable>
<h:outputText value="Data is empty!" rendered="#{empty bean.data}" />

As you see, it can take a boolean expression, so any of the following boolean expression examples are valid:

<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'}" />

The not is by the way an alias for !. More about available EL operators can be found here.

To have a rowindex, make use of UIData#getRowIndex():

<h:dataTable binding="#{table}">
    <h:column><h:outputText value="#{table.rowIndex + 1}" /></h:column>
</h:dataTable>
BalusC
Thanks BalusC for the quickest reply. I could understand that we can use the above combinations in EL. but my question is<h:dataTable width="700" columnClasses="col1,col2,col3" cellspacing="2" headerClass="head" value="#sMSReportBean.smsReport}" var="dataItem"> <h:column > <f:facet name="header"> <h:outputText value="SNo"></h:outputText> </f:facet> <h:outputText value="#{dataItem.rowIndex}"></h:outputText> </h:column>
Paul
+1  A: 

    <h:column>
        <f:facet name="header">
            <h:outputText value="S.No"></h:outputText>
        </f:facet>
        <h:outputText value="#{row+1}"></h:outputText>
    </h:column>
     .
     .

i achieved it with using tomhawk

Paul