Change button after clicking JSF

0

I've got the following problem, I have these two buttons that do:

X: Retrieves the value of a graph +: Adds the value of a graph

Ineedittolooklikethis:WhenIclicktheXbutton

Itswitchestothe+button,astheyhavedifferentfunctionsasyoumightnotice.

Myviewiscurrentlyso:

<p:columnwidth="30">
                <p:commandButton id="valorSelect" value="x"
                    actionListener="#{statusView.selecionarView}" update=":novoform:grafico" >
                    <f:attribute name="projetoSelecionadoNaView" value="#{projeto}" />
                </p:commandButton>
                <p:commandButton value="+"
                    actionListener="#{statusView.addView}" update=":novoform:grafico" >
                    <f:attribute name="projetoSelecionadoNaView" value="#{projeto}" />
                </p:commandButton>
</p:column>
    
asked by anonymous 17.10.2016 / 20:01

1 answer

0

If I understand correctly, you want the user to click one button to disappear and the other to stay in place. You can use the 'rendered' attribute of JSF with a boolean expression or variable that you switch at the time you want. I got more or less your code and I made an example already inside a table:

 <h:form id="novoform">

        <p:dataTable id="grafico" value="#{trocaBotaoBean.listaTeste}" var="nome" >
            <p:column headerText="Action" >
                <p:commandButton rendered="#{!trocaBotaoBean.adicionandoValor}"
                                 id="valorSelect" value="x" actionListener="#{trocaBotaoBean.adicionar()}"
                                 update=":novoform:grafico" />
                <p:commandButton rendered="#{trocaBotaoBean.adicionandoValor}"
                                 actionListener="#{trocaBotaoBean.retirar()}"
                                 value="+"
                                 update=":novoform:grafico" />
            </p:column>
            <p:column headerText="VALORES">
                <h:outputText value="#{nome}" />
            </p:column>
        </p:dataTable>

    </h:form>

ManagedBean:

public class TrocaBotaoBean {

private boolean adicionandoValor;

public TrocaBotaoBean() {

}

public void adicionar() {
    this.adicionandoValor = true;
}

public void retirar() {
    this.adicionandoValor = false;
}

public boolean isAdicionandoValor() {
    return adicionandoValor;
}

public List<String> getListaTeste() {
    List<String> nomes = new ArrayList<>();
    nomes.add("ZEUS");
    nomes.add("THOR");
    nomes.add("RÁ");
    return nomes;
}
}

I hope I have helped.

    
17.10.2016 / 23:13