Hide column at editing time

Asked

Viewed 155 times

1

I have a registration screen with some attributes, in which at the time of editing I do not want to load the password, because I just want to change the name and email, I mean, I want to hide the password column only in editing.

Note: All CRUD is working.

Customer registration.xhtml:

<p:fieldset legend="Clientes">
    <h:panelGrid columns="2">
        <p:outputLabel value="Nome: " for="nome" />
        <p:inputText id="nome" value="#{cadastroClientesBean.cliente.nome}" />

        <p:outputLabel value="E-mail: " for="email" />
        <p:inputText id="email" value="#{cadastroClientesBean.cliente.email}"/>

        <p:outputLabel value="Senha: " for="senha" />
        <p:password id="senha" value="# {cadastroClientesBean.cliente.senha}" 
          required="true" requiredMessage="Senha obrigatória" />

        <p:outputLabel />
        <p:commandButton value="Salvar" action="# {cadastroClientesBean.gravar}"
            icon="ui-icon-disk" update="@form" />
    </h:panelGrid>
</p:fieldset>

Customer consultation.xhtml:

<p:dataTable value="#{consultaClientesBean.clientes}" var="cliente">
    <p:column headerText="Nome">
        <h:outputText value="#{cliente.nome}" />
    </p:column>

    <p:column headerText="E-mail">
        <h:outputText value="#{cliente.email}" />                       
    </p:column>

    <p:column headerText="Ações" width="100" style="text-align:  center">
        <p:button icon="ui-icon-pencil" title="Editar" outcome="/admin/CadastroClientes">
            <f:param name="id" value="#{cliente.id}" />
        </p:button>

        <p:commandButton icon="ui-icon-trash" title="Excluir"
            process="@this" update="@form"
            action="#{consultaClientesBean.excluir}">
            <f:setPropertyActionListener value="#{cliente}" target="#{consultaClientesBean.clienteSelecionado}" />
        </p:commandButton>
    </p:column>
</p:dataTable>

Note: All CRUD is working.

1 answer

0


Usually in the edition the id will not be null, since it was created in the bank and everything else.

If that’s true, you can wear something like this:

<h:panelGroup rendered="#{cadastroClientesBean.cliente.id eq null}">
    <p:outputLabel value="Senha: " for="senha" />
    <p:password id="senha" value="#{cadastroClientesBean.cliente.senha}" 
                  required="true" requiredMessage="Senha obrigatória" />
</h:panelGroup>

If you have any more specific rules you can do something in the controller, or even in XHTML, if you are in context.

Browser other questions tagged

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