How do I clear a <p:messages> from the form by Bean?

Asked

Viewed 414 times

2

I have the following situation: 1. I have a xhtml with <p:tabView> with id="tab"; 2. In this tabview I have 3 tabs and each one with its photons and <p:messages> with their respective id;

What’s the matter? In tab 1 I have the main record, the others are children of this record and need to display only when a code is generated. So far so good, I have an attribute in the Boolean bean that checks if the ID is different from "0" and in the tabs I am using the attribute "Renderer".

When I enter the record in the main tab and the ID is generated, I update the tabview (id = tab) and on the return of the method inform the user that the record has been saved.

The problem! When I update the tab so that the tabs are displayed, the <p:messages> each one is also updated with the message from the main tab.

There’s a way I can clear a component by id through the bean?

All help will be welcome!

Fragment of the Bean

        // define mensagem de sucesso
    messages.info("Atividade salva com sucesso!");

    // atualiza componentes na view
    RequestContext.getCurrentInstance().reset(":frmAtividade:tab:frmEnvolvidos:msg-envolvidos");
    RequestContext.getCurrentInstance().update(Arrays.asList("frmAtividade:tab:aba1:msg-principal","frmAtividade:pnl-cabecalho",
            "frmAtividade:painel-responsavel","frmAtividade:tab"));

Fragments of the xhtml

                    <p:tab title="Envolvidos" id="aba-envolvidos" rendered="#{cadastroAtividadeBean.abaEnvolvidos}" disabled="#{!cadastroAtividadeBean.abasAtivas}">
                    <h:form id="frmEnvolvidos" >
                        <p:messages id="msg-envolvidos" />
                        <p:toolbar id="toolbar-principal">
                            <f:facet name="left">
                                <p:commandLink value="Cancelar" title="Cancelar"
                                    action="#{cadastroAtividadeBean.cancelar()}"
                                    styleClass="btn btn-dark"
                                    immediate="true">
                                </p:commandLink>

                            </f:facet>
                        </p:toolbar>
  • Have you tried using RequestContext.getCurrentInstance().reset("idDoComponente");?

  • Weslley I did the implementation and it didn’t work. See I reset after updating the other components. There is precedence in these calls?

  • You can post your code?

  • I supplemented the question with bean fragments and xhtml

  • Reset at the end of your method.

  • I put and yet the message continues to be displayed.

Show 1 more comment
No answers

Browser other questions tagged

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