Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ADF Custom Component design and onunload/onbeforeunload

User732717-OracleOct 31 2012 — edited Oct 31 2012
First, a caveat: I'm fairly unfamiliar with Javascript and ADF and basically learning on the fly as part of this project, so I wouldn't be surprised if some of my questions are basic.

I am currently designing a custom ADF Faces component that serves as a way to access our legacy application within a new ADF application. The legacy application is being abstracted as a web service which we access internally in the ADF custom component.

The issue I'm having is that the legacy app has a request/release paradigm where a resource needs to be explicitly requested then released when no longer needed. The team responsible for designing the web service is exposing the request() and close() functions, and every call (including close, obviously) then necessitates the use (as parameter) of a resource identifier that I received via the request() call. In pseudo-code:

String resID = webServiceClient.request(arguments...);
webServiceClient.call1(resID, arguments...);
webServiceClient.call2(resID, arguments...);
webServiceClient.release(resID);

While the earliest I need to have requested that resource is during the rendering phase (for the server-side part of the component), at least some of the calls are later done on the client-side part of the component (via a servlet), so I cannot simply release the resource right after being done rendering. When we render again we may or may not need to request a new resource. In the later case we no longer need the old resource so we can release it before requesting the new one. However, in the vast majority of cases the resource should only be released after the user has stopped using our application, i.e. when they leave the application web page.

I've been looking into the window.onunload/onbeforeunload callbacks in Javascript as a potential method of doing this. Ideally, the handling for onunload would be strictly contained within the Javascript code that defines the client-side part of our rich component so as to be transparent to people uptaking our component. Right now though, I'm still experimenting as a proof of concept with a sample test application uptaking our component and adding the onunload override directly into the jspx webpage as a Javascript resource. Even then I'm already encountering issues which may be due to my inexperience.

My first attempt looked like this:
<af:document...>

<af:resource type="javascript">
window.addEventListener('beforeunload',
function (){performUnloadEvent()},false);

function performUnloadEvent() {
var eventSource = AdfPage.PAGE.findComponentByAbsoluteId(<id>);
var event = new AdfCustomEvent(eventSource,
"pageUnload",
{args:'noargs'},false);
event.queue(true);
}
</af:resource>
...
<my:component ...>
<af:serverListener type="pageUnload" method="#{MyTestBean.onUnloadHandler}"/>
</my:component>

If I created a button that calls performUnloadEvent directly this worked, but using either IE or Firefox I would not receive notification of the unload event in my managed bean when closing the tab or navigating away from the page using the back button. I traced down into the queue call and it seemed to be adding it properly to the queue but never actually transmitting the events back to the server. I tried using eventSource.broadcast(event); instead and that did result in my onUnloadHandler being called, but it also forced a re-rendering of the page which caused an exception throw on the server due to the browser having moved away from the page (an exception for socket being closed or something similar).

So already I'm a bit confused as to what I'm doing wrong. More importantly, the next step consists of creating an af:serverListener programmatically as part of rendering as well as having the window.addEventListener call being done as part of the initialization of our client-side component. So any input on how to do those things would be welcome. But I'm sure I'm missing something basic here and that if I don't grasp that at least I'll just have more problems later on.

Edited by: user732717 on Oct 31, 2012 12:50 PM

Edited by: user732717 on Oct 31, 2012 12:55 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 28 2012
Added on Oct 31 2012
0 comments
483 views