How to intercept <p:dialog> CLOSE event and STOP it

UI Components for JSF
schlebe
Posts: 212
Joined: 25 Sep 2015, 13:32
Location: Colmar-Berg (Luxembourg)

03 Feb 2016, 11:36

I agree with you.

I will only display a warning message that advises the user that it risk to lost his work if he close the Dialog panel.

To do this, I need a specific event that currently don't exist or happens too late ! (I think)

I have created an issue (Change Request) on Primefaces GITHUB.
PrimeFaces 6.2.4
Mojarra 2.2.13
Glassfish 4.1

mipe1122
Posts: 2
Joined: 02 Dec 2016, 14:07

10 May 2017, 12:33

What is the progress of this issue? I would like a solution for this as well.

schlebe
Posts: 212
Joined: 25 Sep 2015, 13:32
Location: Colmar-Berg (Luxembourg)

21 Feb 2018, 18:07

@kukeltje that has answered to same question on StackOverflow :D

You propose that I analyze the code ... well ... I have now make that.

But I have a little question:

If a make an "correction", where must I do it ?

1. directly in PrimeFaces code downloaded from GITHUB ?

or

2. in overriding hide() function of PrimeFaces.widget.Dialog() object ?

I don't know if second solution is possible, but I'm interesting to search in this direction.

If you think that second solution is possible, how can I obtain PrimeFaces.widget.Dialog() object from onLoadDialog() method() that is called just after dialog has been loaded ?

Thank for any help
PrimeFaces 6.2.4
Mojarra 2.2.13
Glassfish 4.1

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

22 Feb 2018, 00:33

2 is the better one in the short term.

https://stackoverflow.com/questions/396 ... fic-widget

schlebe
Posts: 212
Joined: 25 Sep 2015, 13:32
Location: Colmar-Berg (Luxembourg)

22 Feb 2018, 11:03

ok, I'm approaching the solution ...

Currently, I think that I have found the JQueryWidget using following code :

var wgDialog = jQuery(".ui-dialog").children(":first-child");

The problem is that I use a DialogFramework and not a simple <p:dialog>.

The html code that I can see on browser is

Code: Select all

<div
    id="FormSession:j_idt271:0:CtcActionTable:0:j_idt280_dlg" 
    class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-shadow ui-hidden-container  ui-draggable ui-resizable ui-overlay-visible" 
    data-pfdlgcid="ec2f04a9-5381-41f7-96a1-caab0f56b7ff" 
    data-widgetvar="FormSession_j_idt271_0_CtcActionTable_0_j_idt280_dlgwidget" 
    role="dialog" 
    aria-labelledby="FormSession:j_idt271:0:CtcActionTable:0:j_idt280_dlg_title" 
    aria-hidden="false" 
    aria-live="polite" 
    style="width: 80%; height: auto; left: 167.5px; top: 32px; visibility: visible; z-index: 1016; display: block;"
    >
    <div class="ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top ui-draggable-handle">
        <span class="ui-dialog-title">CTC input: 56826</span>
        <a class="ui-dialog-titlebar-icon ui-dialog-titlebar-close ui-corner-all" href="#" role="button">
            <span class="ui-icon ui-icon-closethick"></span>
        </a>
    </div>
    <div 
        class="ui-dialog-content ui-widget-content ui-df-content" 
        style="height: 90vh;"
        >
        <iframe ...
My question now is : How can I find the PrimeFaces widgetvar to override it ?

Is JQuery widget equivalent to PrimeFaces widget ? (I think NO, but I'm not sure)

Another question will be:

When I have found a PrimeFaces widget contained in DialogFramework, can I use .parent() or jq.parent() to find PrimeFaces.widget.Dialog not JQuery widget ?
PrimeFaces 6.2.4
Mojarra 2.2.13
Glassfish 4.1

schlebe
Posts: 212
Joined: 25 Sep 2015, 13:32
Location: Colmar-Berg (Luxembourg)

22 Feb 2018, 16:45

I have found how to intercept CLOSE event ... :D

Code: Select all

            var jqDialog = jQuery(".ui-dialog.ui-overlay-visible",window.parent.document).children(":first-child");
            var sWidgetName = jqDialog.attr('data-widgetvar');
            var wgDialog = window.parent.PF(sWidgetName);

            wgDialog.hide = function()
                {
                alert("OnHide()");    
                console.log('hide() in dialog');
                //PrimeFaces.widget.Dialog.hide();
                //PrimeFaces.widget.Dialog.protopype.hide();
                //this.hide();
                // __super__.hide();
                //this.jq.hide();
                }
I have only one problem ... it is

How can I call PrimeFaces.widget.Dialog.hide() to close the windows ?

I have tried a lot of instruction that are all in comment // but none of them works (except if I have badly tested ... it is also possible)
PrimeFaces 6.2.4
Mojarra 2.2.13
Glassfish 4.1

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

23 Feb 2018, 10:44

schlebe wrote:
22 Feb 2018, 16:45
How can I call PrimeFaces.widget.Dialog.hide() to close the windows ?
It is not clear to me what how want to achieve and what you mean by this

schlebe
Posts: 212
Joined: 25 Sep 2015, 13:32
Location: Colmar-Berg (Luxembourg)

23 Feb 2018, 15:35

@Kukeltje: I have found a solution to my problem.

The code I have posted previously is not correct.

This code provides from a JQuery.each() instruction that I have simplified and this doesn't work.

I have posted a Question on StackOverflow about that and I will come back to this forum when I have the simplified response.
PrimeFaces 6.2.4
Mojarra 2.2.13
Glassfish 4.1

kwutzke
Posts: 201
Joined: 20 Jul 2012, 21:35

07 Apr 2021, 11:39

Older topic but still an issue. If you need to intercept *before* the close action, the solution is to exchange the X button's click() function to click onto the dialog's desired no/cancel button.

See this issue: https://github.com/primefaces/primefaces/issues/1001
PrimeFaces 13, Mojarra 4.0, WildFly 31, Jakarta 10 + PrimeReact

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 46 guests