Is it possible to trigger action in backing bean on page unload event?

Hi,
There is a RichPopup in my page which has a Listener to save data or not by user choice "Data change detected, do you want to save those changes?"
I've tried with the javascript event 'window.onbeforeunload', but this way must be fit with a Servlet function which I am not allowed to use.
The attibute 'onunload' in the tag '<af:document>' seems useless. Even there is few description or example in the 'Tag Reference'.
So, is it possible to trigger action in backing bean on page unload event? Thanks in advance for helping.
Viva

Hi Frank
Thanks for helping, I've tried in your way. My codes are like below:
Page codes:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1" clientComponent="true" title="viva test">
      <af:resource type="javascript">
        if (!window.addEventListener) {
            // alert('window.addEventListener is not supported in IE8. Override it!');
            window.addEventListener = function (type, listener, useCapture) {
                window.attachEvent('on' + type, function() {listener(event)});
        window.addEventListener('beforeunload', function (){performUnloadEvent()}, false);
        function performUnloadEvent() {
          var eventSource = AdfPage.PAGE.findComponentByAbsoluteId('d1');
          //var x and y are dummy variables obviously neeed to keep the page
          //alive for as long it takes to send the custom event to the server
          var x = AdfCustomEvent.queue(eventSource, 'handleOnUnload', {args:'noargs'}, false);
          var y = 0;
      </af:resource>
      <af:serverListener type="handleOnUnload" method="#{vivaTestBean.testOnUnload}"/>
      <!--
      <af:form id="f1">
        <af:commandButton text="Unload" id="cb1" action="unload"/>
      </af:form>
      -->
    </af:document>
  </f:view>
</jsp:root>The backing bean codes:
public class VivaTestBean {
    public VivaTestBean() {
    public void testOnUnload(ClientEvent clientEvent) {
        System.out.println("Thanks God");
}The first way which triggers a 'unload' event by clicking a button DO WORKS. :)
But when I changed the triggered way by changing the <af:document> to clientComponent as what you did, the 'onbeforeunload' event won't come out when I refreshed or closed the page.
That doesn't make sence, since I think the two ways to trigger a 'unload' event are the same.
Edited by: 841766 on 2011-3-7 上午1:13

Similar Messages

  • Is i possible to trigger a workflow from the creation of an event in iCal

    Is i possible to trigger a workflow from the creation of an event in iCal
    Or is is possible to create a workflow to ad events to an iCal calendar which then triggers the workflow or is combined with the ad events workflow.
    Graeme

    Hmm, nope. Not that I'm aware of. Very few apps allow you to hook scripts directly to user activity. Finder* is a notable exception. iCal's "publish" feature has the ability to auto-update after user activity, but you'll either need dot mac accounts or your own webdav server to get that working.
    I'd re-consider the idea of triggering a periodic workflow with iCal. That way if the computer is shut down or asleep, iCal will wait to run the workflow at its next opportunity. You could hide the unsightly repeating events in a second calendar so they're out of the way.
    The next best thing is to write a faceless AppleScript application with a long-duration idle handler. The user would simply add it to their login items in System Preferences. This would also resume its cycle after sleep or shutdown.
    Yet another option is to write an AppleScript that can register itself in the crontab. This has the advantage of running at a predictable time. If you're careful, you can even set the script to wake up or power on the computer as necessary.
    * Folder action scripts can be triggered when files are created, moved, or deleted, but not when they're merely updated. This probably rules out much of iCal's activities in ~/library/application support/ical/.

  • Executing Javascript AFTER the action in Backing Bean

    I have a commandButton on my JSP which is bound to a method in my backing bean by the action attribute. However, I also have a Javascript function call in onClick. But, the Javascript function call is always executed first and then my action method is executed. Is there a way to execute the action method first and THEN the Javascript call? I simply just want to popup a message that says 'Save successful' or something to that effect.

    put a onload on your body.
    The javascript function reads a form value and if a certain condition is true you show the alert.
    For example, i've this to clean up error messages. (JavaScript)
    // Cleans the application error messages if there are jsf errors
    function cleanErrorMessages(){
        if(document.getElementById('form1:jsfErrorMessages') != null){
            document.getElementById('form1:applicationErrorMessages').innerText='';
    }

  • Is there any way to create backing bean, After page gets created?

    Hi
    Any one can please answer to my quick question !!!
    Is there any way to create the backing bean ,after a jsf page gets created using ADF ..?
    When i first time created the jsf jppx page i unchecked the option to generate backing bean, but later some time I would like to have backing bean for the newly created page. so is there any way to create backing bean ...?
    Thanks in Advance

    Have your page in the visual design mode then go to the Design->Page Properties menu and you'll be able to select auto-bind on the second tab.

  • Firing a method of backing bean on Page Load

    Hi all,
    Can anyone tell me how a method of the backing bean can be fired when the corresponding jsf page loads in the browser...
    in fact some data is to be fetched from the server at the time of page load and rendered in one of the fields ... kindly help me in this regard ...
    thanks in advance,
    Neeraj Upreti

    You can use a constructor or initialization block of the bean for this or maybe even introduce lazy loading in the getters, all depending on the expensiveness of the actual logic.
    If you're using JSF 1.2, you can also use the beforePhase attribute of the <f:view> to specify a method which is to be fired on beforePhase of the view. You can also add @PostConstruct annotations to the methods which are to be fired on construction of the bean.

  • Create backing bean after page created - 11g

    Is there a way in JDev 11g to create a backing bean (bb) for a page fragment after the page fragment is created?
    I know you can create the bb a time of page creation, but how about after then?

    I have an editable form that is showing values for the current row.
    When I click 'CreateInsert' with immediate="true" (to avoid validation) the old values stay populated in the form. I want to clear the values so the form comes back empty on refresh.
    I figured that I would add an actionListener method on the backing bean in which I programmatically set the submitted values to null (those values coming in on the request from the current row).
    I started the following thread to solve a problem, which lead to this thread:
    stop client validation (11g)

  • ADF BC/Faces - Order of validation / backing bean action problem

    Hello,
    I want the user to enter the same "operation date" into all adf faces table rows created in one batch (one transaction).
    So I removed operation date field from the table and added "unbound" date field above the table. The date field value is then copied into all new rows in background. This process is invoked from backing bean from Commit button actionListener method.
    The problem is the validation of the operation date in entity is executed before a new date value is copied into the date attribute (validation of model is in JSF lifecycle executed prior invoking actions in backing beans).
    It means the user can enter dead lock when he enters invalid date (for example date higher then a valid value).
    Then after commit:
    1. First validation is ok (wrong date value haven't been copied into model yet)
    2. backing bean copy action is executed - model now contains wrong date value
    3. Validation before commit isn't successfult - error message is displayed
    4. User corrects the date value and presses commit again but:
    5. First validation is not successful - model still contains recent wrong date value - error message is displayed again
    6.There is no way out from this situation
    I'm going to override lifecycle to be able to invoke copy method before validation cycle. Is this solution acceptable? Do you have any other suggestion?
    Thank you.
    Rado

    hi Rado
    Would it make sense to design your ADF BC View Objects in some kind of master-detail shape that fits your data?
    View Object : OperationMaster (OperationDateAttr, ...)
    View Object : OperationDetail (OperationAttr1, OperationAttr2, ...)
    View Link : OperationDetailForMasterVL (based on some attribute that keeps the detail rows together)
    You would need some Application Module method that does the "row batch setup", but it look like your already have something like this.
    A change to OperationMaster.OperationDateAttr could update all its detail rows date attribute.
    I think that building a UI on this would be less "view layer dependant".
    Just a suggestion.
    regards
    Jan Vervecken

  • Web services and ADF 11g- get Result from backing bean

    I'm executing an action from backing bean (call Web service that returns complex data types)
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("unesiPonudu");
    Object result = operationBinding.execute();
    result is instance of oracle.adf.model.adapter.dataformat.XMLHandler$DataCollection but DataCollection is not accessible.
    How to get results from method?
    Tnx,
    Andreja

    Hi,
    there should be a result iterator in the Executables section which cotnains the result. If not, create it from the WS result entry in the DC palette. Once this iterator gets updated, you get the data from this iterator as it would be the case of a table accesses the WS
    Frank

  • Remove unwanted backing bean binding

    Hi All,
    My JSFX page has around 200 fields and I have to manipulate only a few fields in the backing bean. When I use this method to bind the UI components with the backing bean Design--> Page Properties ---> Component Binding ---> Auto Bind, all the page UI components get bound. This creates unnecssary binding and my backing bean java files becomes quite messy and runs into 5000 lines. Is it possible to remove the unwanted ones manually without causing any harm. What's the best practice by the way.
    Thanks
    Edited by: user5108636 on Mar 10, 2011 8:38 PM

    Hi,
    This creates unnecssary binding and my backing bean java files becomes quite messy and runs into 5000 lines
    This exactly is why the auto-generate option for backing beans is disabled by default in JDeveloper. There is no functionality in the IDE to remove unneeded bindings (how would the tool be able to tell what you need and what you don't need given that managed beans can be referenced from other managed beans and are referenced from EL in the component binding property).
    Best practices for working with backing beans is to not create them by default and instead use managed bean that you turn into backing beans (which is when they have a page component binding reference) only when needed. This way you stay in control
    Sorry, I have no better answer for this
    Frank

  • Session backing beans and multiple navigator windows sharing session

    Hi let's suppose i have a web and page1, page2 and page3 that should share the backingbean. Normal navigation goes from page 1 to page 2 to page 3.
    I do not want a backing bean per page because i need to share data between my pages. The immediate solution is to put this bean in session context and use it in each page. But this has severe drawbacks:
    - The backing bean is the same each time I access any page, and I want a new bb to be used each time the user requests for page 1
    - When a user has more than one navigator window sharing session, and on each window he is navigating through pages 1 to 3, there can be a big mess because he is accessing to the same bb from both windows.
    So I would like to find a solution that permit the user to navigate from both windows as if the windows had its own session.
    Any hint?
    Thnx

    I have a similar problem as described .
    I hava one window with enterable fields and when you click on a button it opens another window .Both forms are backed by the same bean .since both forms are nearly the same .
    The bean is a managed bean in request scope .
    when I fill in the first window with values and click on the link it opens the second but the first windows elements and now empty .
    Even though it is in Request scope when the second window is being loaded the bean is re-initialized . I would expect a new intance of this bean to be created for the second window .
    This is how I am calling the second window .
    <h:commandButton id="newRequestItem" action="#{requestItem.createNewRequestItem}" rendered="#{createActivationRequest.displayCreateLinks}" onclick="openNewPage('NewRequestItem.jsp');"
    image="images/show_all.gif" title="new request">
    <h:outputText value="new request" styleClass="toolbar-command"></h:outputText>
    </h:commandButton>
    function openNewPage(url)
         aqcbwin= window.open(url, "newRequestItem","toolbar=no, scrollbars=1");
    aqcbwin.moveTo(50, 50);
    target="_new";
    //target="_blank";
    aqcbwin.focus();
    any ideas to what is wrong and how I can correct this .
    Thanks for your help .
    Mark

  • What is difference between Managed Bean and Backing Bean?

    What is difference between Managed Bean and Backing Bean? Please guide me how to create them and when to use them?
    Please post sample for both beans.

    Hi,
    managed beans and backing beans are quite the same in that the Java object is managed by the JavaServer Faces framework. Manage in this respect means instantiation. The difference is that backing beans contain component "binding" references, which managed beans usually don't. Do backing beans are page specific versions of managed beans.
    Managed beans are configured either in the faces-config.xml file, or using ADF Faces and ADFc, in the adfc-config.xml file
    Frank
    Edited by: Frank Nimphius on Jan 31, 2011 8:49 AM

  • Dynamic Action on page unload

    Hi folks
    On one page of my app, I would like to save several page items to session state if the user clicks a tab to load another page. I am doing this so that if the user later returns to the first page, their work in progress can be restored from session state.
    As there are many items on the page and our internet connection is slow, I don't want to save each page item after it is changed or loses focus. I thought the "page unload" event would be perfect for this. However, it does not seem to work.
    I have no condition attached to the event. I have defined one true action to be fired, which executes a null pl/sql block and submits the main page items to save. This technique works fine in other cases, but in this case the page items do not get saved.
    According to firebug, I cannot even see the DA get triggered.
    Does anyone have any tips for this kind of DA event usage, or a better alternative technique?
    Thanks for any advice.
    Regards
    CS

    Add another JavaScript true action that fires before/after the PLSQL displaying an alert message so you know if the D.A is triggered.
    I created the same it seems to be working fine with redirects,page submits and even URL modification requests, and is showing the message before any page unload.

  • Backing Bean Design Issue

    Hi,
    I am new to JSF, we recently decided to move from JSF, as part of a rewrite.I have struts background.
    I have skimmed many JSF books including Core JSF, JSF inAction and many online resources.
    But i still have not been able to get any recommendation/best practice ABOUT Best practice
    for desigining BACKING BEANS for a big enterprise project.
    Almost all resources detail 2 available methodologies i.e.
    1) Have backing bean per page, which doest seem OO way. And if i move
    input components between pages, i have to modify the backing bean.
    2) Or have backing bean per business functionality. For example in my domain, 1 backing bean
    for User General Info, 1 backing bean for Driver History, 1 Bean for Vehicle Information.
    I would appreciate if i could get some input from experts in the area, to give some pointers,
    As this question is bound to come up in every JSF implementations. Having some common guidelines
    would greatly help.
    Thanks a lot
    GP

    Here is a pattern that worked well so far for us:
    Have a backing bean per transaction. Meaning if a transaction consists of multiple pages, you will still have one.
    However this transaction bean is not responsible for assembling data used by each page. Its main role is workflow, validation, and collecting data selected by user as pages are traversed as well as managing the actual transaction.
    It is typically a very thin bean with a scope of session and persists until transaction is completed.
    Now each page may display a different set of data like employee list in a datatable,...etc
    Assembling the data required to be displayed in a datatable will the responsibility of another bean type referred to as data bean. Please note that data beans could be used by different transactions or even different pages across transactions.
    There is a very loose coupling between a trx bean and a data bean (they really are not aware of each others). They essentially play different roles. The page knows about both the data and trx beans. But the reverse is not true. If you happen to use data beans with a scope of session, you will also need some clean up mechanism in your framework when a transaction is completed.
    I am sure others may have come across different patterns.

  • Trigger Backing Bean Action from Java script

    Hello
    I'm quite new to JSF, Would like to know how we can trigger a bcaking bean action method using java script as part of form submit.
    Already I added one commandbutton with an action method defined in backing bean, But our requiremnt is to trigger the same action even if the user submits form by pressing Enter key.
    Targeted device is Windows Mobile IE ( In IE Mobile, we can't track onkeydown, onkeyup, onkeypress, onmousemove, onmousedown and onmouseup event. )
    1. How the JSF binds a backing bean method with JSF commandButton control on runtime. I didn't find any hidden value corresponding to this commandButton.
    2.How we can trigger a bcaking bean action method using java script as part of form submit
    Thanks
    Jobinesh

    thanks a lot for the replies. I'll try it out.
    But one question, just because of curiosity
    1. How the JSF binds a backing bean method with JSF commandButton control on runtime. I didn't find any hidden value/or any other flag corresponding to this commandButton from the genarted html for the correspondant jsf soure.

  • Is it possible to set the firefox back button to a custom action in the context of a websocket connexion?

    Simply, is it possible to set the firefox back and forward button to custom javascript function to navigate in a websocket application.
    Thanks in advance

    You may get lucky, especially as Today is a "Sumo Day" with more contributors around than usual. Such a question tends to be slightly off topic, being a hack of a standard Firefox installation.
    What I would suggest is that you try other forums, either a specialist linux forum or the popular Mozillazine forums: http://forums.mozillazine.org/index.php

Maybe you are looking for

  • Why do I need to verify my email address?

    As with any successful global Community, we are constantly at war with Spam.  The people behind spam don't care that their spam is not welcome here.  They simply want to get you to view their message.  This small win is enough to justify their effort

  • Dimension name is not displayed when all dimvals are selected

    I have a dimension Price Range diemnsion which is multiselect Or. If I select all dimVals of Price Range the Price range is still displayed in left side of jspref application. We have another dimensions Ad Feature which is also multiselect Or. If I s

  • Wls 6.1 on solaris 8 intel: native libraries missing (libmuxer.so ...)

    It seems that the native libraries for sparc only are included in WLS 6.1??? #file libmuxer.so libmuxer.so: ELF 32-bit MSB dynamic lib SPARC Version 1, dynamically linked, not stripped Where can I get the intel version? # ./startWebLogic.sh LD_LIBRAR

  • Restoring "lost" to my itunes library

    Getting this error message for many songs in my iTunes library on my iMac.The song XXX could not be used because the original file could not  be found. Would you like to locate it?

  • CD performance

    I have looked where I know to look, however I am unable to degtermine what the read/write specifications are for the SD card slot on my W520. I want to get the appropriate SD cards. Any pointer where I may find this spec? Thanks in advance.... Mike