geeehhdaa
geeehhdaa

Reputation: 822

JSF: Empty space caused by rendered attribute

How can I get rid of the empty space by components not rendered via rendered attribute?

I want to display a list of objects in a dataTable and sort them by a property they have. I do it likes this: view plaincopy to clipboardprint?

<t:dataTable value="#{someBean.values}" var="value">  
    <h:column>  
        <f:facet name="header">  
            <t:outputText value="X" />  
        </f:facet>  
        <h:panelGroup rendered="#{value.property eq 'X'}">  
          <!-- some stuff -->  
        </h:panelGroup>  
    </h:column>  
    <h:column>  
        <f:facet name="header">  
            <t:outputText value="Y" />  
        </f:facet>  
        <h:panelGroup rendered="#{value.property eq 'Y'}">  
          <!-- some stuff -->  
        </h:panelGroup>  
    </h:column>                 
</t:dataTable>  

It will display one item every row only, because of the rendered thingy. How can I avoid this? I stumpled upon this also on other occasions...

Thank you!

Upvotes: 1

Views: 1504

Answers (2)

BalusC
BalusC

Reputation: 1108732

Use a single column and render in there.

<t:dataTable value="#{someBean.values}" var="value">  
    <h:column>  
        <f:facet name="header">  
            <t:outputText value="#{value.property}" />  
        </f:facet>  
        <h:panelGroup rendered="#{value.property eq 'X'}">  
          <!-- some stuff -->  
        </h:panelGroup>  
        <h:panelGroup rendered="#{value.property eq 'Y'}">  
          <!-- some stuff -->  
        </h:panelGroup>  
    </h:column>                 
</t:dataTable>

Upvotes: 1

niksvp
niksvp

Reputation: 5563

It is obvious to display one item every row with datatable.

You can better have two different datatables, one rendering for x and other rendering for y and adjust your css accordingly that looks like two column of the same table. Or else using richfaces, <rich:subTable> would help you, such as having two subTable in a single dataTable

Upvotes: 2

Related Questions