1

I ran into a bit of a problem with Primefaces dialog and the actionListener on my commandButton.

To provide a bit of backdrop:
The application I maintain currently uses an older version of ICEfaces. I've been tasked to find out if replacing it with a current version of Primefaces (I'm currently using 5.2.6) would provide benefits in terms of speed/reaction time and also what we would need to do, to replace the framework. We have to do this with the minimum amount of work and so rebuilding all our pop-ups is kind of out of the question.

Now, to the problem at hand:
I'm trying to replace the old ace:dialog with p:dialog and so far it was as easy as just switching out the tags. The dialogs work almost as before but I have a weird problem with the h:commandButton.
I picked out one of the pop-ups, which is used to display error messages, to work on a proof of concept. I know that other pop-ups suffer from the same problem however. Here is the code for this pop-up, which I stripped down to the bare necessities.

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<p:dialog id="ErrorPopupID" widgetVar="panelPopupErrorWidget" 
    position="center" modal="true" resizable="false" draggable="false" 
    closeOnEscape="false" header="Errors"
    visible="#{errorPopupBean.renderErrorPopup}">
        <h:panelGroup style="width:320px;">
            <div style="height:218px;padding:5px;">
                <h:outputText escape="false" value="Error text"/>
            </div>
                <h:form>
                <div style="padding-left:5px;">
                    <h:commandButton id="errorPopupCloseButton"
                     value="Close"
                     actionListener="#{errorPopupBean.closeErrorPopup}"/>
                </div>
            </h:form>
        </h:panelGroup>
</p:dialog>

As you can see the pop-up contains a button that basically just closes the pop-up and also clears the message list. For a reason I can not figure out, the action is only triggered when I click the button a second time. When I click it for the first time, nothing seems to happen from the users point of view.
I happen to have a PhaseListener however, so I know that upon the first click a request is send to the server, but that only phases 1 and 6 of the life-cycle are executed. Only on the second click the entire life-cycle - including INVOKE_APPLICATION - is processed and the action fires. But I can't figure out why.

Here is what I've tried without success:

  • replaced h:commandButton with p:commandButton
  • tried different nesting of the h:form (was originally outside of p:dialog)
  • moved the ui:include for the pop-up directly in front of </h:body>
  • tried both FULL and PARTIAL for primefaces.SUBMIT
  • various variations of all of the above
  • EDIT: I also tried three different versions of Primefaces, 4.0.10 and 5.0.10 in addition to the 5.2.6 I'm actually using, just to see if it was a glitch in this particular version of PF.

I'm at a loss here and don't know what else to try. It worked with ICEfaces so I think it must work with Primefaces too.
I checked the other questions here as well, but they either deal with a different scenario or p:dialog not working at all. Mine works, but just not exactly right.

Sebastian_H
  • 349
  • 3
  • 13
  • How is the dialog closed? With javascript in the backing bean? Try ` oncomplete="PF('panelPopupErrorWidget').hide()">` – opfau Nov 20 '15 at 14:13
  • @opfau The value of the dialogs `visibility` attribute is determined by the bean. Which means the action method just clears a list and then `errorPopupBean.renderErrorPopup` returns false. This works and is not the problem however. The pop-up closes as expected. The problem is that the action event is only triggered on the second click on the button, not on the first. I can clearly see that in the debugger and `PhaseListener` output. – Sebastian_H Nov 20 '15 at 16:41

1 Answers1

0

Can you try p:commandButton with attribute ajax="false".

hekko
  • 292
  • 1
  • 2
  • 6