Bug? Unable to add ActionListener using Anonymous class.

Hi,
I come accross one strange behaviour while adding ActionListener to RCF component.
I am trying to add the ActionListener in the managed bean using the Anonymous.
We can add the actionListener to a button using following methods. I am talking about the the first case. Only this case is not working. Rest other 2 cases are working properly.
Case 1:
class MyClass {
     RichCommmandButton btnTest = new RichCommmandButton();
     public MyClass(){
          btnTest.addActionListener(new ActionListener(){
               public void processAction(ActionEvent event){
Case 2:
class MyClass implements ActionListener {
     RichCommmandButton btnTest = new RichCommmandButton();
     public void processAction(ActionEvent event){
<af:button binding="#{myClassBean.btnTest}" actionListener="#{myClassBean.processAction}"/>
Case 3:
class MyClass implements ActionListener {
     RichCommmandButton btnTest = new RichCommmandButton();
     public void addActionLister(){
          //Use EL to add processAction(). Create MethodBinding
          FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory exprfactory = facesContext.getApplication().getExpressionFactory();
          MethodExpression actionListener =
exprfactory.createMethodExpression(elContext, "#{myClassBean.processAction}", null, new Class[] { ActionEvent.class });
          btnTest.setActionListener(actionListener);
     public void processAction(ActionEvent event){
Java has provided good way to use the Anonymous classes while adding the listeners. It should work with the RCF also.
Some how i found the case 1 usefull, as i can have as many buttons in my screen and i can add the actionListener in one method. Also it is easy to read. I dont have to see the JSPX page to find the associated actionListener method.
Is it a bug or i am wrong at some point?
Any sujjestions are welcome.
- Sujay.

Hello Sujay,
As I said in my previous reply, you can try with request scope. In JSF you shouldn't use the binding attribute very often. I agree that anonymous class is nice, but don't forget that you might be dealing with client state saving here so it cannot be perfectly compared with Swing that maintains everything in RAM. What I think happens with you currently is the following:
1. Bean is created and the button instance as well. The ActionListener is added to the button;
2. The view is rendered and while it is, the binding attribute is evaluated, resulting in the get method of your bean being called;
3. Since the method returns something different than null, the button instance created in 1. get used in the component tree;
4. The tree's state is saved on the client, since your class isn't a StateHolder, nor Serializable, the StateManager doesn't know how to deal with it so it gets discarded from the saved state and maybe from the component itself (would have to debug the render view phase to be sure);
5. The postback request arrives, the tree is restored. When the handler reaches the button, it call the bean that returns the same instance that was used in the previous tree (since not request scoped), which is BAD because the remaining of the tree is not made of the same object instances, but rather new deserialized ones. The component then gets updated from the client state saved in 4, this might also be where the listener get removed (again debugging would tell you this, but I would tend more with the previous possibility). Note that with a request scoped bean you would have to add the listener during the first get method call (by checking if the component is null) or in the constructor as you're doing right now. It would be a very clean way and you could give the request bean (and thus the listener) access to the conversation scoped bean through injection which is very nice as well.
6. The invoke application phase occurs and the listener is no longer there.
Btw, this isn't a rich client issue, more a specification one. I'm curious if it works in a simple JSF RI application, if it does then I guess it would be a bug in Trinidad and/or rich client state handling architecture (using FacesBean).
Regards,
~ Simon

Similar Messages

  • Unable to start Tomcat using runtime class in windows 98

    hi,
    I am using a runtime class which calls a batch file, that calls statup.bat for starting tomcat.
    This works perfectly in windows NT,2k. But on win 98, the tomcat window opens and closes within no sometime.
    In my class i call the first batch file starter.bat using
    Runtime.getRuntime().exec("%COMSPEC% /c start e:/starter.bat");
    (I tried with command.com also...)
    Starter.bat has the line
    call E:\jakarta-tomcat4.1\bin\startup.bat.
    Is there anyother way to start the tomcat process and keep it running on windows 98. Anyone with anyclues pls help.
    Thanks in advance.

    This is the Runtime class i am using... Sometimes tomcat gets closed and sometimes just hangs... (putting it in for better understanding..)
    public class Starter {
         public static void main(String[] args) {
              String com = "%COMSPEC% /c start
    C:\\PACS\\SFAApp\\tomcat\\startup.bat";
                   try     {               
                        Runtime rt = Runtime.getRuntime();
                        Process pr = rt.exec (com);//Starting tomcat
                        try
                             pr.waitFor();     
                        catch (Exception e)
                             e.printStackTrace();
                   catch (IOException ie) {
                        System.out.println("IOException caught" + ie);
                        ie.printStackTrace();

  • Unable to access files using FilePermission class .

    Hi frineds !!!
    I m new to java networking..plz help in finding the solution of my problem*..Its urgent !!*
    FilePermission perm=new FilePermission("D:/contacts","read");
    AccessController.checkPermission(perm);
    and it is giving an error :
    Exception in thread "main" java.security.AccessControlException: access denied (java.io.FilePermission D:/contacts read)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at test.Main.main(Main.java:38)
    plz help me out...

    amit.trical wrote:
    But it should grant me the permission.Are you saying you think that creating the FilePermission object should grant the permission? Or are you saying that calling the checkPermission method should grant the permission?
    Neither of those are true. Creating the FilePermission object gives you something about which you can ask if it's permitted or not. And calling the checkPermission method asks that question.
    To grant the permission to read that file, you must do that via the policy file. Java code can't grant itself any permissions (for obvious reasons).

  • BUG: Unable to add tag library to component palette on linux (Ubuntu)

    As already discussed in the thread problem with adding Sun JSF RI v1.2 as a new library in JDeveloper 10.1.3.1 i have problems adding the Apache Trinidad (faces) tag library to the component palette. Actually the adding is not the problem and initially after adding it, it works. But when closing JDeveloper and restarting the components have disappeared while they are still selected in the Edit Tag Libraries menu. This problem only occurs on Linux and not under windows.
    Kind Regards,
    Andre Jochems

    Hi,
    Thanks for reporting this issue
    Frank

  • ActionListener as nested class, anonymous class etc.

    I'm programing my own text editor and im trying to decide in what way to implement an ActionListener for JMenuItems.
    I've got 3 possible ideas of how to implement it.
    First way is to implement the ActionListener in the same class as the JMenu and use a switch statement or a fairly long if-else statement.
    Second way is to create nested classes for each ActoinEvent.
    public class OuterClass {
         //Some random code here...
         private class ActionClass implements ActionListener{
              public void actionPerformed(ActionEvent e) {
                   //Random code.
    }And final way is creating anonymous classes adding ActionListeners for each JMenuItem.
    menuItem.addActionListener(new AbstractAction(){
    public void actionPerformed(ActionEvent e) {
    });But i can't decide on wich of these are the moste correct and accepted way.
    Could someone point me to the right direction?
    Edited by: Idono on Jun 3, 2010 7:36 PM

    the only time you would do the first one would be if you wanted several ActionListeners to do the EXACT SAME THING.
    Then you just write the "actionClass" one time, and have each Component use it.
    private class ActionClass implements ActionListener{
              public void actionPerformed(ActionEvent e) {
                   //Random code.
    menuItem.addActionListener(new ActionClass());
    menuItem1.addActionListener(new ActionClass());
    menuItem2.addActionListener(new ActionClass());
    menuItem3.addActionListener(new ActionClass());But (as the other person mentioned) usually you use anonymous classes because each component has different actions.
    menuItem.addActionListener(new AbstractAction(){
    public void actionPerformed(ActionEvent e) { ... }
    menuItem1.addActionListener(new AbstractAction(){
    public void actionPerformed(ActionEvent e) { ... }
    menuItem2.addActionListener(new AbstractAction(){
    public void actionPerformed(ActionEvent e) { ... }
    });

  • Anonymous class for Event handling isnt working

    my anonymous class is not working.i keep gettin an invalid method declaration. i think im either mispelling something somewhwere or missing a curly.
    public SpouseGUI(){
         add(new JButton("test"){
    addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e){
                   JOptionPane.showMessageDialog(null,"hi","hi",3);
                   }//end method
              }//end action listener
    }//end anonymous class
                   setSize(100,100);
    setVisible(true);
    //end of constructor

    Yeah, you shouldn't use anonymous classes like that; that's not the purpose of anonymous classes. If you really, really, want to use an anonymous class, you will have to use a initializer block, like this:
    p.add(new JButton("test") {
        { // initializer block
            addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    // do something
    });But there is absolutely no point in doing that, it's much better to just create the button and add the action listener:
    JButton btn = new JButton("test");
    btn.addActionListener(...);
    add(btn);

  • Where is the anonymous class in this? (lotsa code)

    When I compile ThreadPool.java, I get three classes: ThreadPool.class, ThreadPool$WorkerThread.class, and ThreadPool$1.class. I understand the first two, but I can't figure out where the anonymous class is coming from. Could it be some kind of automatically-generated wrapper class caused by the fact that all accesses to the Queue object are within synchronized blocks? Curiosity attacks!
    Thanks,
    Krum
    ThreadPool.java:
    package krum.util;
    * A thread pool with a bounded task queue and fixed number of worker threads.
    public class ThreadPool {
       protected Queue queue;
    public ThreadPool(int threads, int taskQueueSize) {
       queue = new Queue(taskQueueSize);
       /* create the worker threads */
       for(int i = 0; i < threads; ++i) {
          Thread t = new Thread(new WorkerThread());
          t.setDaemon(true);
          t.start();
    * Queues a task to be executed by this ThreadPool.  If the task queue is
    * full, the task will run in the calling thread.  (Could easily be modified
    * to throw an exception instead.)
    public void doTask(Runnable task) {
       boolean added = false;
       synchronized(queue) {
          if(!queue.isFull()) {
             queue.add(task);
             added = true;
             queue.notify();
       if(!added) task.run();
    * Tests if the task queue is empty.  Useful if you want to wait for all
    * queued tasks to complete before terminating your program.
    public boolean queueEmpty() {
       synchronized(queue) {
          return queue.isEmpty();
    private class WorkerThread implements Runnable {
    public void run() {
       Runnable task;
       while(true) {
          task = null;
          synchronized(queue) {
             try {
                if(queue.isEmpty()) queue.wait();
                else task = (Runnable)queue.getNext();
             } catch(InterruptedException e) { break; }
          if(task != null) task.run();
    } /* end inner class WorkerThread */
    } /* end class ThreadPool */Queue.java:
    package krum.util;
    * Implements a FIFO queue for storage and retrieval of objects.  This class
    * is not synchronized.
    public class Queue {
         /** circular buffer containing queued objects */
         protected Object[] queue;
         /** index of next object to be returned */
         protected int nextReturn;
         /** index in which to store next object inserted */
         protected int nextInsert;
    public Queue(int capacity) {
         queue = new Object[capacity];
         nextInsert = 0;
         nextReturn = 0;
    public boolean isEmpty() { return(queue[nextReturn] == null); }
    public boolean isFull() { return(queue[nextInsert] != null); }
    public void add(Object obj) throws QueueException {
         if(queue[nextInsert] == null) {
              queue[nextInsert] = obj;
              ++nextInsert;
              nextInsert %= queue.length;
         } else throw new QueueException();
    public Object getNext() throws QueueException {
         if(queue[nextReturn] != null) {
              Object obj = queue[nextReturn];
              queue[nextReturn] = null;
              ++nextReturn;
              nextReturn %= queue.length;
              return obj;
         } else throw new QueueException();
    } /* end class Queue */QueueException.java:
    package krum.util;
    public class QueueException extends RuntimeException { }

    I can't explain why it happens, but I've seen this
    behaviour before. I found that it was to do with an
    inner class (WorkerThread in your code) having a
    private constructor - if I made my inner class
    constructor at least package (default) access, then
    the anonymous class was no longer created.
    The generated default constructor for a class has the
    same access modifier as the class, so in your example,
    the default constructor that the compiler generates is
    private.
    I suspect the problem will go away if you either:
    1. Remove the private modifier from the WorkerThread
    class declaration.
    or:
    2. Add a no-args constructor to the WorkerThread
    class, and don't specify an access modifier.Yes, the reason is the private constructor. After decompile using JAD, the reason seems to be: if a private inner class does not explicitly have any constructor, a default no-arguments private constructor is created, and seems this default constructor can't be accessed directly (in source code, it can). So, another no-private constructor (package accessible) is created automatically (with an argument of Object's type), and the
    new WorkThread();is actually like this:
    new WorkThread(null);
    private class WorkThread implements Runnable{
       private WorkThread(){}
       WorkThread(Object obj) {
          this();
    }and I would guess it's using anonymous class tech to achieve this like:
    new WorkThread(null) {
       WorkThread(Object obj){
          this();
    }The JLS should have specified this situation.

  • Add jar files and use those classes at the runtime

    Hi All,
    I need to add some jar files at the runtime depends on which the user selects where the jar file is located and i need to import those classes in other class for some functionalities . I could add jar files by using the URLClassLoader and Class.forName("myjar.myclassname") is also succeeded and i have no clue how to use those classes with in the jar file as i couldn't import those classes also in the source because the jar files are being added at the runtime(This leads to class not found exception at the compile time).
    I had found a complicated way of using those classes after being added at the run time as below.
       Class clazz = Class.forName(myClass);
                final Method method = clazz.getDeclaredMethod(requiredMethod, new Class[]{URL.class});
                final Object returned = method.invoke(clazz.newInstance(), new Object[]{request}); but, its really pain to use in this way in all the places.
    Does any of you have simpler suggestions on how to achieve this?
    Thanks,
    Venky.

    Thanks jschell. Yes, you are right. I had found that using reflection API is the only way to load classes at the run time. But according to our application using reflection makes the application little complex, so while start of the application or during other modifications, i am overwriting my jar file to the latest one using FileChannel class as below
          FileChannel ic = new FileInputStream("new.jar").getChannel();
          FileChannel oc = new FileOutputStream("old.jar").getChannel();
          ic.transferTo(0, ic.size(), oc);
          ic.close();
          oc.close();After this code is executed, our application totally uses the new jar file.It is little fast than using reflection. Is this a good idea?

  • I'm unable to add the email address for iMessage, that I was using before iOS 7 to my iPhone, because it says that it is "in use by another device," but I have no other devices.  How do I resolve this so I can add this email address to my iPhone?

    I'm unable to add the email address for iMessage, that I was using before iOS 7 to my iPhone, because it says that it is "in use by another device," but I have no other devices.  How do I resolve this so I can add this email address to my iPhone to send and recieve iMessages?

    Sync your iPhone to iTunes, and see if that does the trick.  Also you could try a Soft Reset with no Risk to Data.  Holding down both the Sleep button and the Home button until the Apple logo appears and then waiting for the Reset to bring you iPhone back to the lock screen.    Are you trying to add the email at Settings>Messages>Send and Receive from (2 Addresses) your iPhone number and your email address?

  • Unable to add aspx file to document library using REST and JSOM in SharePoint Hosted App

    Hi,
    I am unable to add an aspx file to document library.  I was actually trying to create a WIKI page and upload to Pages library but that wasn't working so I tried simple document library.  It keeps failing with Access Denied error.  I have checked
    the blocked types and aspx is not included.  I can upload it directly from the browser so that shouldn't be the case.  I have read that it can be achieved with CSOM but I need this to work with a SharePoint Hosted App.  Here is my JSOM:
    factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
        context.set_webRequestExecutorFactory(factory);
        appContextSite = new SP.AppContextSite(context, hostweburl);
        oWeb = appContextSite.get_web();
        oList = oWeb.get_lists().getByTitle('Documents');
        fileCreateInfo = new SP.FileCreationInformation();
        fileCreateInfo.set_url("mywiki.aspx");
        fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
        fileContent = "<%@ Page Inherits=\"Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" %> <%@ Reference VirtualPath=\"~TemplatePageUrl\"
    %> <%@ Reference VirtualPath=\"~masterurl/custom.master\" %>";
        for (var i = 0; i < fileContent.length; i++) {
            fileCreateInfo.get_content().append(fileContent.charCodeAt(i));
        newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);
        context.load(newFile);
        context.executeQueryAsync(function () {
            alert('yo');
        }, function (sender, args) {
            alert(args.get_message() + '\n' + args.get_stackTrace());
    If I change the file extension to "txt", it works.  Same with REST implementation, it works with "txt" but fails with "aspx".  Maybe what I am trying to do will not work using JSOM or REST.  Any suggestions?  Your
    help is always appreciated.
    Regards,
    kashif

    Your code works fine in both my on-premises and SharePoint Online. I have given the app full control, so I suspect this is a permissions issue. I would check your permissions on your appmanifest. Must be something to do with publishing permissions. Try
    giving full control and work the permissions down.
    Blog | SharePoint Field Notes Dev Tools |
    SPFastDeploy | SPRemoteAPIExplorer

  • How to add external library in class path folder for use in Java call-out?

    Hi,
    I am working with Java callout component in OSB 12c using Jdeveloper.
    Thing is Jar what i am using to perform conversion of json to xml that using external libraries.
    When i have give reference of my project jar to java callout it doen't found external libraries.
    Could you please tell me how to add external libraries in class path folder or How to use to add it through web-logic server ?
    Thanks,
    Pavan

    Hi,
    Thanks, I have solved issue.
    We can add on following path in windows pc:
    C:\Users\your_usename\AppData\Roaming\JDeveloper\system12.1.3.0.41.140521.1008\DefaultDomain\lib
    One you add your external lib here then do restart weblogic server instance.
    Now, you have that external lib or jar in use.
    Cool!

  • [svn:bz-trunk] 8910: Bug: LCDS-936 - Should have better error message in servlet log if server in services-config .xml is configured to use wrong class.

    Revision: 8910
    Author:   [email protected]
    Date:     2009-07-29 14:22:26 -0700 (Wed, 29 Jul 2009)
    Log Message:
    Bug: LCDS-936 - Should have better error message in servlet log if server in services-config.xml is configured to use wrong class.
    QA: Yes
    Doc: No
    Checkintests: Pass
    Ticket Links:
        http://bugs.adobe.com/jira/browse/LCDS-936
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/MessageBrokerServlet.java

    After many hard working days.i finally found the error cause,i needed to make weblogic datasource also ADF doesnt work on internet explorer browser,it works on safary.hope it helps somebody

  • TS3147 I have been unable to add an HP Photosmart C4480 printer to my existing printer list using a USB connection. My current operating system is OS X  version 10.9.1. It seems that software is available, but it doesn't work. Any suggestions?

    I have been unable to add an HP Photosmart C4480 printer to my existing printer list using a USB connection. Software seems to be available and thought I had downloaded it, but doesn't work. Any suggestions?

    Try deleting the printer, restarting, and trying software update again.
    If that doesn't work, you can download the entire HP package here:
    http://support.apple.com/kb/DL907

  • Since the last software update, I am unable to add new contacts or change existing contacts - neither if I use the green Phone app nor using the brown Contacts app. Any suggestions?

    since the last software update, I am unable to add new contacts or change existing contacts - neither if I use the green Phone app nor using the brown Contacts app. Any suggestions?

    *Update*
    I thought I had found the offending 'app' namely "Songpop."
    I regularly use "Songpop" on my phone late at night via my wifi connection.
    All enteries on my phonebill are at midnight (even though I have a data allowance it was excluded from allowance). I switched 3G off on Friday, played "Songpop" at midnight and at the exact time I got a "Server Error" message.
    I posted a message on the "Songpop" support forum.At first they said this was a problem relating to my ISP.
    I have spoken to my ISP and asked if there are connection drops at the time I have been billed (ie to establish if my wifi dropped and 3G kicked in without my knowledge) and have been advised that there aren't any connection drops at that time.
    "Songpop" have now responded that "This is an issue to take up with Apple Support"  see: http://support.songpop.fm/songpop/topics/playing_songpop_on_phone_via_wifi_but_i ncurring_download_data_charges_for_3g_useage?utm_content=topic_link&utm_medium=e mail&utm_source=reply_notification
    Hopefully someone at Apple can respond ....

  • Unable to add AP Invoice using DTW

    Unable to add AP Invoice using dtw. Customer is trying to upload negative values,Both in the line and header.
    We get the following error :Invalid Total [OPDN.doctotal]

    Hi,
    Depending on the SBO version, you cannot do negative AP invoices; as Gordon mentioned, you want to import those as AP credit memos. I believe it's in 8.8 that you can have negative AP/AR transactions.
    Heather

Maybe you are looking for