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

Asked

Viewed 341 times

4

I have a <p:hotkey> which is the Primefaces component for working with shortcuts. Every time I press Ctrl + 1 two new fields appear on the page but I would like every time I press this combination the data that is in imputText Codigo and Descrição are added to a list.

For example, I squeeze Ctrl + 1 two new fields appear and the values of the first fields are added in a list. I am trying as follows:

Campos:

<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 adicionarCodigos:

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

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

    contador++; 
}

Notice I have one System.out.println that shows the listaServicos, but it is coming null. That is, it is not taking the values of the imputText. How can I get these values when entering with the shortcut?

  • Just to make sure I understand... When using the shortcut will fill the item with the data input and the same item will be added to the list?

  • When I use the shortcut it takes input data and plays in a list

1 answer

3


You must inform the form which data will be synchronized Interface > Bean

That’s what the attribute is for process where you inform 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. Even, could use only the p:hotkey:

<p:hotkey bind="ctrl+1" 
    actionListener="#{cadastroReembolsoBean.adicionarCodigos()}"    
    update="pnlCadastroServico"
    process="@this codigoServico descricaoServico">
</p:hotkey>
  • Hello, @info.sistemas! I see this is your first answer on the site. Do a tour to learn how Stack Overflow works. In your case, try to edit the answer to look more like a direct answer to our colleague’s problem, because what you wrote fits more like a comment.

  • 2

    @Dherik, you were right. I edited and formatted according to a reply. Thanks for the feedback.

  • Thank you @info.sistemas I think was missing the process even.

  • @info.sistemas that was good "JSF wizard". I agree with you. rsrs

  • @info.sistemas, started well! : D. Welcome!

Browser other questions tagged

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