You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by James <ja...@gmail.com> on 2008/12/15 10:46:49 UTC

[Trinidad] Using window.opener with Dialog Framework

Hi,

I'm trying to access the window that open's my dialog using Javascript
with window.opener, but this reference is null. What I'm trying to do
is the following:

1. User selects items in a table on main page
2. User clicks button which opens dialog page containing a print view
of the items
3. User closes the dialog page, once a javascript confirm passes, the
main page submits to the backing bean which performs some processing,
and the main page is then reloaded with the updated items

1 and 2 is fine, I have that working, its step 3 that I am having
trouble with... it doesn't seem possible with the Trinidad Dialog
Framework (maybe by design).

Maybe some more clarification:

========
main page:
========
...
<script type="text/javascript">
function callBack() {
  alert('called');
  if (confirm('Proceed')) {
    // submit page to allow backing bean to process items
  }
}
</script>
...
  <tr:commandButton id="printButtonId"
                    styleClass="button"
                    text="Process"
                    action="dialog:print"
                    partialSubmit="true"
                    useWindow="true"
                    windowWidth="700"
                    windowHeight="500"
          />
...

=====
dialog
=====
...
<head>
<script>
function doOnunload() {
  alert('doOnunload');
  window.opener.callBack();
}
</script>
</head>
<f:view>
<body onunload="doOnunload();">
...

---------------------------

The alert('doOnunload') popup shows fine, so the javascript is being
run, the problem is that window.opener is null. Anyone have any ideas
how I can get my desired outcome? I hope I'm not being too vague.

Thanks in advance,

James Barrow

Re: [Trinidad] Using window.opener with Dialog Framework

Posted by James <ja...@gmail.com>.
Hi Rafa,

Thanks for your reply. I'm aware of the returnListener attribute.

However, the way the application should work is to first confirm that
the document was printed successfully, and only then to proceed
processing. If not, to re-show the dialog for printing again. The
previous implementation did this via Javascript, by calling a function
on the opener window, which re-displays the printing/dialog window, or
goes back to the server to process.

I could call the process method in my backing bean in the
returnListener, however I first need confirmation that printing was
successful from the user before doing this. The way I was going to try
handle it is by having a 'close' button that's not displayed when the
media is print, that way the user will now have to click the 'close'
button instead of closing the window, which will confirm with the
user, then the returnListener can process and update components... I
think. Although then the problem still remains that on closing of the
dialog, the user isn't first asked for confirmation before processing
continues...

So instead I'm just doing away with the dialogs and navigating to the
print page, which just has buttons that aren't displayed when the
media is print.

Cheers,

James

On Mon, Dec 15, 2008 at 12:40 PM, Rafa Pérez <ra...@gmail.com> wrote:
> tr:commandButton has an attribute 'returnListener' that points to a
> method in the backing bean that gets executed when the dialog is
> closed, i.e., when
> RequestContext.getCurrentInstance().returnFromDialog() is called.
> Maybe this is what you need.
>
> HTH,
>
> -- Rafa
>
> On Mon, Dec 15, 2008 at 10:46 AM, James <ja...@gmail.com> wrote:
>> Hi,
>>
>> I'm trying to access the window that open's my dialog using Javascript
>> with window.opener, but this reference is null. What I'm trying to do
>> is the following:
>>
>> 1. User selects items in a table on main page
>> 2. User clicks button which opens dialog page containing a print view
>> of the items
>> 3. User closes the dialog page, once a javascript confirm passes, the
>> main page submits to the backing bean which performs some processing,
>> and the main page is then reloaded with the updated items
>>
>> 1 and 2 is fine, I have that working, its step 3 that I am having
>> trouble with... it doesn't seem possible with the Trinidad Dialog
>> Framework (maybe by design).
>>
>> Maybe some more clarification:
>>
>> ========
>> main page:
>> ========
>> ...
>> <script type="text/javascript">
>> function callBack() {
>>  alert('called');
>>  if (confirm('Proceed')) {
>>    // submit page to allow backing bean to process items
>>  }
>> }
>> </script>
>> ...
>>  <tr:commandButton id="printButtonId"
>>                    styleClass="button"
>>                    text="Process"
>>                    action="dialog:print"
>>                    partialSubmit="true"
>>                    useWindow="true"
>>                    windowWidth="700"
>>                    windowHeight="500"
>>          />
>> ...
>>
>> =====
>> dialog
>> =====
>> ...
>> <head>
>> <script>
>> function doOnunload() {
>>  alert('doOnunload');
>>  window.opener.callBack();
>> }
>> </script>
>> </head>
>> <f:view>
>> <body onunload="doOnunload();">
>> ...
>>
>> ---------------------------
>>
>> The alert('doOnunload') popup shows fine, so the javascript is being
>> run, the problem is that window.opener is null. Anyone have any ideas
>> how I can get my desired outcome? I hope I'm not being too vague.
>>
>> Thanks in advance,
>>
>> James Barrow
>>
>

Re: [Trinidad] Using window.opener with Dialog Framework

Posted by Rafa Pérez <ra...@gmail.com>.
tr:commandButton has an attribute 'returnListener' that points to a
method in the backing bean that gets executed when the dialog is
closed, i.e., when
RequestContext.getCurrentInstance().returnFromDialog() is called.
Maybe this is what you need.

HTH,

-- Rafa

On Mon, Dec 15, 2008 at 10:46 AM, James <ja...@gmail.com> wrote:
> Hi,
>
> I'm trying to access the window that open's my dialog using Javascript
> with window.opener, but this reference is null. What I'm trying to do
> is the following:
>
> 1. User selects items in a table on main page
> 2. User clicks button which opens dialog page containing a print view
> of the items
> 3. User closes the dialog page, once a javascript confirm passes, the
> main page submits to the backing bean which performs some processing,
> and the main page is then reloaded with the updated items
>
> 1 and 2 is fine, I have that working, its step 3 that I am having
> trouble with... it doesn't seem possible with the Trinidad Dialog
> Framework (maybe by design).
>
> Maybe some more clarification:
>
> ========
> main page:
> ========
> ...
> <script type="text/javascript">
> function callBack() {
>  alert('called');
>  if (confirm('Proceed')) {
>    // submit page to allow backing bean to process items
>  }
> }
> </script>
> ...
>  <tr:commandButton id="printButtonId"
>                    styleClass="button"
>                    text="Process"
>                    action="dialog:print"
>                    partialSubmit="true"
>                    useWindow="true"
>                    windowWidth="700"
>                    windowHeight="500"
>          />
> ...
>
> =====
> dialog
> =====
> ...
> <head>
> <script>
> function doOnunload() {
>  alert('doOnunload');
>  window.opener.callBack();
> }
> </script>
> </head>
> <f:view>
> <body onunload="doOnunload();">
> ...
>
> ---------------------------
>
> The alert('doOnunload') popup shows fine, so the javascript is being
> run, the problem is that window.opener is null. Anyone have any ideas
> how I can get my desired outcome? I hope I'm not being too vague.
>
> Thanks in advance,
>
> James Barrow
>