Executing code when a listener is added

Is there a way for an event generater to execute certain code whenever an event listener registers with it? If so, where would you have to put this code?

You write the appropiate support class for listeners to this event, that is, the class which handlers add<Something>Listener, and register only an instance of this class as a listener of the original event. In the add<Something>Listener, before adding the object in the listeners list, you execute the code you wish.
If this doesn't seem as an appropiate solution, will you please provide some more details? The topic is interesting, thanks.

Similar Messages

  • I Want to Execute Code When a session Expires

    hi friends,
    I want to execute some code when ever a user ends his session. I came to know this can be accomplished by using HttpListener. But if any body give a example it will be lot more clear.
    Thank Q
    Srinivas

    Or SessionListener. - MOD

  • Execute code when IE Browser closes

    Help!  I'm trying to find a way to run a SQL statement when a user closes a IE window (X's out).  I've found information on the onBeforeUnload event but I've been unsucessful at getting it to run.
    Does anyone have another suggestion?  Is it even possible to execute code upon closing a window?
    Thanks!!!

    Thanks ilssac.  I figured this was the case based on my research but I thought I'd present it to the Forum just to be sure.
    Basically, I've been asked to limit the number of logins to a small Coldfusion application.  I've coded it so that I increment a counter in the DB and I decrement it when the user logs out properly (by clicking a logout link).  But if the user just closes the window then the decrement doesn't happen and this created problems.
    If you have any suggestions I would really appreciate it.
    Thanks for your time!!!!

  • Execute code when task flow is finished

    I have two task flows: TFBrowseRecs and TFUploadFile.
    I initiate calling of TFUploadFile from view (by af:button) inside TFBrowseRecs.
    TFUploadFile has return-value-definition which is is used to return value which is created in TFUploadFile.
    TFUploadFile is opened as new transaction as Dialog and has two task-flow-return activites, one as <commit/> and other for <rollback/>.
    When <commit/> activity occurs I can pass return value back to TFBrowseRecs successfully.
    I want also to execute some code/action in TFBrowseRecs immediately when TFUploadFile is finished (insert new record into VO).
    I think, I can define EL for method call inside <after-listener> which is defined inside TFBrowseRecs, but I can't find any useful example for this approach.
    Btw, I could execute this code/action inside TFUploadFile but I want that TFUploadFile is black box for TFBrowseRecs and other TFs.
    1. Is this approach OK?
    2. Can you show some example how such a method should look like
    Regards,
    Sašo
    Edited by: Sašo C. on 29.9.2011 0:36

    I doubt finalizer is right place regarding my requirements:
    I want called TF (TFUploadFile) to be black box for calling TF (TFBrowseRecs). In TFUploadFile I just insert row in one VO and return ID of inserted row to TFBrowseRecs.
    What do you think?
    Regards,
    Sašo

  • How to execute code when press the ENTER key

    Hello,
    I've write the code in Key-ENTER trigger, but it doesn't work when I press ENTER key.
    Best Regards
    Joe

    Matth M
    Thank you.
    The following msg. from help system shows that key-enter trigger will execute when the ENTER pressing event occurs. Need your more help.
    Regards
    Joe
    >
    (index: "DO_KEY" )
    Executes the key trigger that corresponds to the specified built-in subprogram. If no such key trigger exists, then the specified subprogram executes. This behavior is analogous to pressing the corresponding function key.
    Built-in............Key Trigger............Associated Function Key
    ENTER............Key-ENTER............[Enter]

  • Execute code after Spry region redrawn / added to DOM

    Hi,
    I'm integrating my Spry event data with a YUI calendar.
    Everything is working and event dates are highlighted on the YUI calendar.  There is one last thing I wish to do which is to update the YUI calendar with a Spry Tooltip.  The div regions for the tooltip text are generated dynamically by via a Spry repeating region.  What I am failing to do is attach the tooltips to the YUI calendar after the Spry repeating region has been added to the docuement DOM. So the Spry Tooltip function cannot find the ID of the tooltips.
    I have a dataset observer "onpostload" which seems to fire when the data is loaded but before the document dom has been updated by Spry.  How can I ensure I wait for Spry to update the region and hence DOM with the new data before triggering the tooltip code?
    Cheers
    Phil

    You got different kind of observers in Spry Data.
    - Dataset observers:
         datasetname.addObserver( observer )
    - Spry Region Observers:
         Spry.Data.Region.addObserver( 'region-id', observer );
    The dataset observers send out notifications when there is a event happening inside the Spry Data Sets. The one you mentioned is part of this (onPostLoad). These are great to monitor your data changes, but in your case. You don't want to use these.
    The Spry region observers respond to events that are happening in side the region. For example onPreUpdate, this event is called when the region is about to generate / insert new markup in to your region. But you also got the onPostUpdate. This is the observer you are looking for, it gets called once the region has re-generated its code / html. It gets fired directly after the new HTML has been inserted.
    Small note about the region observers, these require a id= attribute. This id attribute must be placed on the same element as the spry:region. To learn, and read more about the observers i would like to referrer you to this article:
    Data Set and Region Overview
    Its rather large, but using the browser build in find function you should be able to locate the sections about the observers
    Hopes this helps,

  • Executing code on EXIT_ON_CLOSE

    I was wondering how you execute code when a JFrame closes using the X button (ie, without using a menu). Because you don't attach an ActionListener to it, I am unsure as to where I would place code that I would like to execute before the program exits.
    Thanks

    add a WindowListener to the JFrame; windowClosing() will be called when the X is clicked (setDefaultAction is more or less just a convenience method for this)

  • How do I execute some code when a line of a table control is selected?

    Hi,
    I would like to execute some code when a line of a table control is selected.  At the moment I have to select one or multiple rows and then press enter, this forces a screen refresh and my code is executed but I would like the code to be executed as soon as any line is selected.
    I've done something like this using ALV grids and object orientated code but is there a way of doing this in a normal non-OO table control?
    Thanks in advance.
    Gill

    Hi,
    U need to declare a char1 field for marking (mark field).  This will reflect with value 'X' in your tcontrol internal table for all the selected rows. 
    Now u need to handle the okcode for enter in your PAI.
    There u need to loop through the table for all marked fields.
    There after u can do what ever u want.
    Venkat.

  • Scrolling to next range in advanced table when new rows are added.

    I programatically implemented Add New Row in an advanced table.
    "Records Displayed" attribute of advanced table =10, so as log as I add upto 10 new rows the table displays 10 rows,if I add 11th record the new record is appended @ 11th position but I've to choose "Next" link on the advanced table to see the 11th row.Is it possible to show the last rowset in the advanced table when new rows are added?
    The underlaying VO executes the following code when "Add New Row" button is pressed:
    int rCount = this.getFetchedRowCount();
    int rangeSize = this.getRangeSize();
    int rangeStart = this.getRangeStart();
    if (rCount < rangeSize) {
    this.insertRowAtRangeIndex(rCount, newRow);
    } else {
    this.setRangeSize(rCount+1);
    this.insertRowAtRangeIndex(rCount, newRow);
    this.setCurrentRow(newRow);
    To scroll to the 11-20 rows (when added more than 10 rows),I tried with following options, but none of them helped:
    1) int newRangeStart = ( rCount / 10 ) * 10 ;
    this.setRangeStart(newRangeStart);
    2) this.scrollRange(newRangeStart);
    3) this.scrollRange(rCount);
    4) int newRangePage = rCount / 10;
    this.scrollToRangePage(newRangePage+1);
    5) this.getNextRangeSet();
    Please let me if it is possible to achieve.

    What happens if you just add the new row without specifying where to add it ? doesn't it add the new row on the same page as the last row ?
    Thanks
    Tapash

  • Adf valueChangeListener autosubmit=true, execute code after update model

    Hello.
    I'm working with the valueChangeListener and autosubmit="true". I'll try to explain my situation
    with an example.
    jsp:
    <af:form>
         <af:panelForm>
              <af:inputText
                   id="value1"
                   label="Value1"
                   value="#{index.myObject.value1}"
                   autoSubmit="true"
                   valueChangeListener="#{index.changeListener1}"/>
              <af:inputText
                   id="value2"
                   label="Value2"
                   value="#{index.myObject.value2}"/>
         </af:panelForm>
    </af:form>
    backing:
    public class Index {
        private MyObject myObject;
        public Index() {
            myObject = new MyObject();
        public void changeListener1(ValueChangeEvent valueChangeEvent){
              doSomethingWithMyObject(myObject);
        // ... get/set of myObject
    MyObject:
    public class MyObject {
        private String value1;
        private String value2;
        public MyObject() {}
         //getters/setters...
    }In the line doSomethingWithMyObject(myObject) i need myObject with the actual values in the user form.
    in the example above, the first time the page is rendered and shows the inputs
    if the user captures something in the 1st input and then hits the tab to go to the other input
    the valueChangeEvent is fired, and the code in "index.changeListener1" executed, but at this moment
    the model (myObject) hasn't been updated with the data that the user entered (Validation Phase).
    So i need a way to execute my code called from the "valueChangeEvent" but after the model has been updated
    Some notes about my problem:
         - The doSomethingWithMyObject(myObject) could update data in myObject
         - About binding="#{x.y}":
         I know i can use the binding attribute in the tag <af:inputText binding="#{x.y}"> and then in the code of
         the changelistener the binded component always have the most recent value from the user,
         but i cant' use that, the method needs a MyObject instance.
         - I don't think create a new instance of MyObject and populate it every time the event fires is a good way
         - doSomethingWithMyObject" is a black box, so i don't know what is going to do with myObject
         - In my problem there are more than 2 inputs there will be N components M listeners.
    What I'm trying:
         PhaseListener:
         I have been implementing a solution with a PhaseListener like
         public void afterPhase(PhaseEvent phaseEvent) {
              // just after UPDATE_MODEL_VALUES phase
              FacesContext f = FacesContext.getCurrentInstance();
            Index i = (Index) f.getApplication().createValueBinding("#{index}").getValue(f);
              // at this point the model is updated
              doSomethingWithMyObject(i.getMyObject);
         public PhaseId getPhaseId() {
            return PhaseId.UPDATE_MODEL_VALUES;
              this works but i don't know if this is the answer according to this post (unanswered at this time):
              http://forums.oracle.com/forums/thread.jspa?threadID=611643
         says something about that PhaseListener is not thread safe and blocks the application with more
         than 1 user.
         A wrapper:
         using the controls binded to the backing
         public class Index {
              private MyObject myObject;
              private CoreInputText inputValue1;
              private CoreInputText inputValue2;
              //listener
              //getters/setters
         }     make a wraper like
         public class MyObjectW {
             private Index index; // wrap the backing index
             public MyObjectW(Index index) {
                 this.index = index;
             public String getValue1(){
                 return (String) index.getInputValue1().getValue();
             public String getValue2(){
                 return (String) index.getInputValue2().getValue();
             public void setValue1(Object v){
                 index.getInputValue1().setValue(v);
             public void setValue2(Object v){
                 index.getInputValue2().setValue(v);
        }and then call in the index backing:
    doSomethingWithMyObject( new MyObjectW(this)); so it will access to the most actual values from user at the valueChangeEvent
    But i really would like some way to execute my code called from the "valueChangeEvent" but after the model has been updated
    so i dont need to wrap or implement PhaseListener
    what do you think, what do you suggest, have any solution or a way to do what I'm trying?
    thank you for your help...
    Message was edited by:
    akanewsted

    Hello Frank, thanks for the response.
    When you say
    "If you need an updated object in this listener then you can update it from the value change listener as well"
    you mean i can update the object by myself with the value from getNewValue()? or is there another way
    to call to update the models at this time ?
    I know i have the methods "getOldValue()" and "getNewValue()" in the "ValueChangeEvent" but what if i need
    the actual value from the user in other control than the one that fires the event
    example
    Two inputs:
    in the input1 the user enters some data
    in the input2 when some data is entered it fires valueChangeListener (autosubmit=true)
    in that case what if i need the value the user just entered in the input1 in the valueChangeListener of
    the input2.
    In general the app I'm working must do:
    dynamically generate the controls in the form (inputs, selects etc)
    Attach the control values to a model ( <af:inputText value=#{model.x}"/>
    sometimes execute some script when a value change in a control (valueChangeListener)
    those scripts uses the model (and needs to be an updated model)
              script = " if (value2 = 'xyz') then value1='abc'; return true;";
    if the model is not updated
    the script will use old values and will be wrong
    or if the script change some value in the model, when the update model phase occurs the value from
    the script is lost.
    that's why i need to work directly with the model and not the values in the ValueChangeEvent
    Is there a way to use something like an action in the change of a control value?
    that way the code will execute in the invoke application phase, can this be done ?
    how i can execute code in the invoke application when a valueChangeEvent occurs ?
    hope this help to explain more my situation.
    Thank you for your help and time.

  • Executing code in NetBeans 3.5.1

    Hi,
    I've been using my own custom Ant scripts within NetBeans to compile code, generate various descriptors and create archive files. I really like using Ant; the only reason I even use an IDE is for editting--it's nice having its spell checking functionality, etc. However, to execute and debug code, I go straight to the command prompt to run my jar. But now I'd like to take the next step: execute and debug un-jarred code within NetBeans.
    Executing code works fine within NB if I don't use packages. However, when I use packages, I get NoClassDefFoundErrors for dependencies. That is, my main class gets found, but its dependencies do not.
    Can someone please show me how it's done in NB 3.5.1? Also, should I create an Ant task to execute my code from within the IDE?
    D:\
    ----+com
    --------+myco
    ------------+myapp
    ----------------+myMain.java              /*this does get found*/
    ------------+mydep
    ----------------+myDependency.java        /*this does not get found*/
    I've searched the NB website, but there is just too much stuff to wade through. And of course, I've searched the forums here too. I'd appreciate any help! Thanks!
    PGynt

    Hi,
    Thanks for replying!
    the d:\ folder needs to be mounted as a filesystem.Please see expanded structure below.
    All dependency classes need to be compiled
    (add them to the project and build all).I'm using Ant to compile within NetBeans. It creates a build directory which mirrors the source code directory structure. Package names are same as directory structure. It all runs fine within a jar, but only outside of NB. Below is an expanded version of my structure. Maybe it will make things clearer.
    If you like ANT, maybe you should
    upgrade to netbeans 4.1 because it uses ANT as it's
    build engine.Sounds good, but it's not in our budget for now. Changes always take so much time.
    D:\
    ----+application/*this directory is mounted and added to project*/
    --------+src  /*this directory is mounted and added to project*/
    ------------+com
    ----------------+myco
    --------------------+myapp
    ------------------------+myMain.java /*this does get found*/
    --------------------+mydep
    ------------------------+myDependency.java /*this does not get found*/
    --------+build
    ------------+com
    ----------------+myco
    --------------------+myapp
    ------------------------+myMain.class  /*this does get found*/
    --------------------+mydep
    ------------------------+myDependency.class /*this does not get found*/
    Is it necessary to add classes to a project for executing a program? Or is mounting the relevant directories enough?
    Again, I'm used to using Ant directly, so I'm sorry if that sounds like a dumb question.
    PG

  • It is possible to programmatically disable the "Executing Code Modules in an External Instance of CVI" feature?

    It is possible to programmatically disable the "Executing Code Modules in an External Instance of CVI" feature within a CVI project?
    I know how to do it manually (Configure > Adapters... > Adapter Configuration).
    Thanks in advance,
    --M

    Yes. TestStand 2.0 added the Engine.CVIAdapter_ExecuteStepsInCVI property.

  • Running abap code when Browser is closed,

    Hi,
    In my application,  need to delete couple of rows in a table when the user closes the browser. In order to do this i have written a JavaScript when executes itself when the browser closes. When i code a alert message it executes fine when the browser closes but, when i write an abap code it gets executed when the page loads itself. I have tried to methods. Both aren't working.
    Method1 :
    <%@page language="abap" %>
    <html>
        <head>
        </head>
      <script language="JavaScript">
        window.onunload = unloadHandler;
        function unloadHandler() {
                    <%
                      delete from ZDATALOCK
                      where auid = sy-uname.
                    %>
      </script>
        <body>
            <tr>
            <td>
               <table  border="0" width="100%" height="100%" align="center">
               <tr>
                   <td>
                   <iframe src          = "mas.do"
                           style        = " overflow:visible; height:100%; width:100%; "
                           name         = "Form"
                           marginheight = "0"
                           marginwidth  = "0"
                           frameborder  = "0">
                   </iframe>
                   </td>
               </tr>
               </table>
            </td>
            </tr>
        </body>
    </html>
    Method2 :
    <%@page language="abap" %>
    <html>
        <head>
        </head>
      <script language="JavaScript">
        function dellock() {
                    <%
                      delete from ZDATALOCK
                      where auid = sy-uname.
                    %>
      </script>
        <body onunload=dellock()>
            <tr>
            <td>
               <table  border="0" width="100%" height="100%" align="center">
               <tr>
                   <td>
                   <iframe src          = "mas.do"
                           style        = " overflow:visible; height:100%; width:100%; "
                           name         = "Form"
                           marginheight = "0"
                           marginwidth  = "0"
                           frameborder  = "0">
                   </iframe>
                   </td>
               </tr>
               </table>
            </td>
            </tr>
        </body>
    </html>
    Kindly help.

    Hi,
    ABAP code is server side and JS is client sides. You can't execute ABAP on the front end. What I suggest is that you submit a form before you actually close a window.
    document.someform.submit();
    window.setTimeout('window.close()',5000);
    The close will only happen after 5000ms.
    Check http://www.devguru.com/Technologies/ecmascript/quickref/win_settimeout.html for details.
    in the oninputprocessing you can do your
    delete from ZDATALOCK
    where auid = sy-uname.
    Also check /people/eddy.declercq/blog/2006/03/20/wake-me-up-before-you-go-go
    Eddy

  • Restrict Company code when i press F4

    Hi,
      Iam having 2 company codes : 1000 and 1100.
      My scenerio : i added tcodes : me22n,me23n,me21n  in one role and assiged to user A and user B.
    If A user login and enter tr.code : me21n then in org.data tab---in company code if i press F4 it will show only one company code (i.e.1000)
    If B user login and enter tr.code : me21n then in org.data tab---in company code if i press F4 it will show only one company code (.i.e. 1100)
       I want to restrict particualr user for particular company code when i press f4 in me21n or me22n tr.code.
    Guide me for the same.
    Thanku

    You will need to use a search help exit to put in an additional validation that performs a check against a users auths for plant.  Your development team will know how to do this.  If you do a search on "search help exit" you will get a few hits on SDN

  • Error NL-00051 when the listener starts up

    Hi,
    I'm getting an error when the listener starts up on my NT4 system. I have Oracl 8.0.4 running and for some reason I get:
    NL-00051: internal error code, arguments: [302], [1], [], [], [], [], []
    Does anybody know why this is happening. The listener no longer works and the DB's are out of use.
    Any help would be appreciated.
    Thanks,
    Mark Willems

    bash-2.05$ oerr nl 51
    00051, 00000, "internal error code, arguments: [%s], [%s], [%s], [%s], [%s], [%s
    ], [%s]"
    // *Cause:  This is the generic internal error code for NPD program
    // exceptions. This indicates that a process has encountered an
    // exceptional condition.
    // *Action: Report as a bug - the first argument is the internal error number
    // The second argument is the "emfi" (err msg file index).

Maybe you are looking for