How to merge columns h: column in JSF?

1

How can I merge columns or rows in JSF 2.0?

Code

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">


    <h:form>
        <h:commandButton action="#{clienteController.novo}" value="CadastrarNovo"/>


    <h:dataTable value="#{clienteController.clientes}" var="cliente" border="1">

    <h:column>
        <f:facet name="header">Codigo</f:facet>
        #{cliente.codigo}
    </h:column>

    <h:column>
        <f:facet name="header">Nome</f:facet>
        #{cliente.nome}
    </h:column>

    <h:column>
        <f:facet name="header">Idade</f:facet>
        #{cliente.idade}
    </h:column>


    <h:column >
        <f:facet name="header">Acao</f:facet>

        <h:commandLink action="#{clienteController.editar}">Editar
            <f:setPropertyActionListener value="#{cliente}" target="#{clienteController.cliente}" />
        </h:commandLink>
    </h:column> 
    <h:column>
        <h:commandLink action="#{clienteController.remover}">Remover
            <f:setPropertyActionListener value="#{cliente}" target="#{clienteController.cliente}" />
        </h:commandLink>
    </h:column>

    </h:dataTable>
</h:form>
    
asked by anonymous 29.09.2017 / 17:01

1 answer

1

You can not do this with <h:dataTable> . If in your project you are using richfaces you can use <rich:dataTable> with colspan in the column:

<rich:dataTable value="#{clienteController.clientes}" var="cliente" border="1">
    <f:facet name="header">
        <rich:columnGroup>
            <rich:column>Codigo</rich:column>
            <rich:column>Nome</rich:column>
            <rich:column>Idade</rich:column>
            <rich:column colspan="2">Acao</rich:column>
        </rich:columnGroup>
    </f:facet>
    <rich:column>#{cliente.codigo}</rich:column>
    <rich:column>#{cliente.nome}</rich:column>
    <rich:column>#{cliente.idade}</rich:column>
    <rich:column>
        <h:commandLink action="#{clienteController.editar}">Editar
            <f:setPropertyActionListener value="#{cliente}" target="#{clienteController.cliente}" />
        </h:commandLink>
    </rich:column>
    <rich:column>
        <h:commandLink action="#{clienteController.remover}">Remover
            <f:setPropertyActionListener value="#{cliente}" target="#{clienteController.cliente}" />
        </h:commandLink>
    </rich:column>
</rich:dataTable>

There are options for primefaces, tomahawk, etc. Or even using html tags and facelets.

    
29.09.2017 / 18:26