3

i have a strange problem with a p:message tag. On page a have a dataTable with data from my db that i can edit in a p:dialog. Once all validations succeds and the update in db is done i refresh the dataTable and add a faces message info to display the succes of the operation. In the front-end i update the form whom contains both the dataTable and the dialog. My problem is that the message is displayed but almost instantly disapears. It's like the message tag is updated with the form. I don't get it.

I have tried to move the message tag in & out of the form in didn't change anything. I have tried to tweak the remoteCommand to update just the dataTable and the dialog but it didn't work.

<p:messages autoUpdate="true" showDetail="true" severity="info,error" />
<h:form id="form">
    <p:dataTable
    style="width: 80%; margin-left: auto; margin-right: auto; text-align:center"
        var="achievement" value="#{achievementBean.listAchievement}">
    ...
    </p:dataTable>

    <p:dialog header="#{i18n['achievement']}" widgetVar="dlg"
        dynamic="true" closable="false" resizable="false" showEffect="fade"
        hideEffect="fade">
        <h:panelGroup id="achievementDetail">
            <p:messages autoUpdate="true" severity="warn" />
            ...
            <h:panelGrid columns="2" style="width: 100%; text-align:center">
                <p:commandButton value="#{i18n['general.submit']}"
                    icon="fa fa-check"
                    actionListener="#{achievementBean.submitAchievement}"
                    oncomplete="if(!args.validationFailed){updateForm();}" />
                <p:commandButton value="#{i18n['general.cancel']}"
                    icon="fa fa-close" action="#{achievementBean.submitCancel}"
                    oncomplete="PF('dlg').hide();" update="@form" process="@this" />
            </h:panelGrid>
            <p:remoteCommand name="updateForm" update="@form" />
        </h:panelGroup>
    </p:dialog>
</h:form>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
K.Sorokin
  • 45
  • 4
  • 1
    I am pretty sure it is because you have auto update=“true” on your messages. If you watch the network traffic with F12 you will see it – Melloware May 27 '19 at 16:55
  • As OP would find out in making a [mcve] in removomg more and more from his/her code and in the emd noticing the removal of what you mention makes it work. Again, [mcve] to the resqueue – Kukeltje May 27 '19 at 22:06

2 Answers2

6

Your concrete problem boils down to this:

<p:messages autoUpdate="true" />

<h:form>
    <p:dataTable ...>
       ...
    </p:dataTable>
    ...
    <p:dialog>
        ...
        <p:commandButton
            action="#{achievementBean.submitAchievement}"
            oncomplete="if(!args.validationFailed){updateForm();}" />
        <p:remoteCommand name="updateForm" update="@form" />
    </p:dialog>
</h:form>
  • The autoUpdate="true" will automatically update the component on every ajax request.
  • The <p:commandButton> invokes an ajax request which adds a message and invokes the updateForm() remote command. The message is displayed on that ajax request.
  • The <p:remoteCommand> invokes another ajax request. But this one doesn't add any messages, so nothing is displayed on that ajax request. In effects, the message displayed in the previous ajax request gets cleared out.

You can use ignoreAutoUpdate attribute of the command component in order to let it ignore any autoUpdate-able component. So your solution is:

<p:remoteCommand name="updateForm" update="@form" ignoreAutoUpdate="true" />

That said, why do you still have both the <p:dialog> and the <p:dataTable> in the same <h:form>? It appears that you didn't take or understood the recommendation in my answer to your previous question p:commandButton doesn't dislpay p:dialog. Therein I recommended to move the <p:dialog> outside the <h:form> and give it its own <h:form>. It makes these things so much easier manageable.

You should always give the <p:dialog> its own <h:form>.

<p:messages autoUpdate="true" />

<h:form>
    <p:dataTable ...>
       ...
    </p:dataTable>
    <p:remoteCommand name="updateForm" update="@form" ignoreAutoUpdate="true" />
</h:form>

<p:dialog widgetVar="dlg">
    <h:form>
        ...
        <p:commandButton
            action="#{achievementBean.submitAchievement}"
            update="@form"
            oncomplete="if(!args.validationFailed){PF('dlg').hide();updateForm();}" />
    </h:form>
</p:dialog>

See also:

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for your answer i understand better why it didn't work. To answer your question about the single form, it's because this code is older than the question that i asked. I didn't forget your recomandation about the form and the dialogs ;-). – K.Sorokin May 29 '19 at 12:34
0

Thanks for yours answers. Sorry about the mre i always forget about it. I'll try to not forget it next time. I finally managed to solve my problem.

  • I added an id to the first <p:message>
  • I added an update of this id in the submit <p:commandButton>
K.Sorokin
  • 45
  • 4