How to add data to a list whenever a p: hotkey is used?

4

I have <p:hotkey> which is the component of Primefaces to work with shortcuts. Every time I press ctrl + 1 two new fields appear on the page, however I would like every time I press this combination the data that is in imputText Codigo % are added to a list.

For example, I press ctrl + 1 two new fields appear and the values of the first fields are added to a list. I'm trying this way:

Fields:

<p:outputLabel value="Código Serviço" />
<p:inputText id="codigoServico" size="40" value="#{cadastroReembolsoBean.servico.codServico}"/>

<p:outputLabel value="Descrição" />
<p:inputText id="descricaoServico" size="46" value="#{cadastroReembolsoBean.servico.descricao}"/>

Hotkey:

<p:hotkey bind="ctrl+1" handler="desenvolvimento()"></p:hotkey>
<p:remoteCommand name="desenvolvimento"
    action="#{cadastroReembolsoBean.adicionarCodigos()}" immediate="true" 
    update="pnlCadastroServico"></p:remoteCommand>

Method Descrição :

public void adicionarCodigos() {
    if (contador < 0) {
        contador = 0;
    }

    solicitacao.getListaServicos().add(servico);
    System.out.println("Serviço Adicionado: "+solicitacao.getListaServicos());

    contador++; 
}

Note that I have a adicionarCodigos that shows System.out.println , but it is coming null. That is, it is not taking the values of listaServicos . How do I get these values when entering the shortcut?

    
asked by anonymous 17.08.2015 / 16:22

1 answer

3

You must tell form what data to synchronize Interface > Bean

This is the process attribute where you enter the ID of the components that will be "synchronized."

For more details, see the JSF wizard response in the English version of Stack: Difference between process and update

I believe this is the key to solving your problem, as described. You could even use only p:hotkey :

<p:hotkey bind="ctrl+1" 
    actionListener="#{cadastroReembolsoBean.adicionarCodigos()}"    
    update="pnlCadastroServico"
    process="@this codigoServico descricaoServico">
</p:hotkey>
    
19.08.2015 / 19:32