How to merge <h:column > columns in JSF?

Asked

Viewed 463 times

1

How can I merge columns or rows in JSF 2.0 ?

tela

Code

<!DOCTYPE html PUBLIC "-//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>

1 answer

1


You can’t do that with <h:dataTable>. If in your project you are using richfaces you can use the <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 and facelets tags.

  • how would you look in Primefaces ??

  • Something like this: https://www.primefaces.org/showcaseui/data/datatable/group.xhtml

Browser other questions tagged

You are not signed in. Login or sign up in order to post.