2 Replies Latest reply: Apr 26, 2012 1:42 PM by 929464 RSS

    ClientListener on Button -  Programmatically

    929464
      Hello,

      Requirement : I need to Create a command button and when you hover your mouse on it, a function has to be called . Everything has to be done programmatically.

      My Procedure: I have already created a RichCommandButton programmatically with a binding to a function(HandleImagePress) which triggers when I click the button. This function inturn creates, populates and displays the necessary information in the form of a popup. However , With the new requirement, I am just supposed to hover onto my button to trigger this function (HandleImagePress). I believe I need to create ClientListener and so I tried it. But it doesnt work the way I want ... :-(

      This is what I have tried:

      public void handleImagePress(ActionEvent event){
      // There is code to create , populate and display and popup . It works fine
      }

      private UIComponent ImageButton(UIComponent parent){
      RichCommandButton img = new RichCommandButton();
      String imagestyle = "width:120pt; height:120.0pt;margin:10.0pt;";
      img.setInlineStyle(imagestyle);
      // Compose method expression to invoke action event handler when button is pressed.
      FacesContext fctx = FacesContext.getCurrentInstance();
      Application application = fctx.getApplication();
      ExpressionFactory elFactory = application.getExpressionFactory();
      ELContext elContext = fctx.getELContext();
      MethodExpression methodExpression =null;
      // Make sure the EL expression references a valid managed bean method. Ensure the bean scope is properly addressed.
      methodExpression = elFactory.createMethodExpression( elContext,"#{pageFlowScope.pinint.handleImagePress}",Object.class,new Class[] {ActionEvent.class});
      // Create the command button action listener reference.
      MethodExpressionActionListener al = null;
      al= new MethodExpressionActionListener(methodExpression);

      img.addActionListener(al);
      // Add new command button to parent component and PPR the component for the button to show.
      parent.getChildren().add(img);
      ClientListenerSet set = img.getClientListeners();
      *if (set == null) {*
      set = new ClientListenerSet();
      img.setClientListeners(set);
      *}*


      set.addBehavior("new AdfShowPopupBehavior('popup',AdfRichPopup.ALIGN_AFTER_END,null,'mouseOver')");
      // set.addListener("mouseOver", "handleImagePress");
      AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
      adfFacesContext.addPartialTarget(parent);
      return img;

      }

      With this code, I need to click on image atleast once to create a popup . Is it possible to call the function without clicking but by just hovering on it? (bcoz the HandleImagePress function takes care of everything regarding to popup)

      Help will be greatly appreciated :-)

      Thank You
        • 1. Re: ClientListener on Button -  Programmatically
          932836
          1. There are no functions in Java. only methods.

          2.
          http://docs.oracle.com/javase/7/docs/api/java/awt/Component.html#addMouseMotionListener(java.awt.event.MouseMotionListener)
          Hope it helps
          addMouseMotionListener(new MouseMotionListener() {
              public void mouseDragged(MouseEvent e) {}
              
              public void mouseMoved(MouseEvent e) {
                  ... whatever you want ...
              }
          })
          • 2. Re: ClientListener on Button -  Programmatically
            929464
            Thank You for the reply, I have created a command button in Jdeveloper, ADF Faces component. It doesn't have "addMouseMotionListener" . So i have tried this way,

            import java.awt.event.MouseEvent;
            import java.awt.event.MouseMotionListener;
            I have tried adding a Mouse event instead of an Actionevent this way ..

            public void handleImagePress(MouseEvent event){
            int m = event.MOUSE_ENTERED;
            System.out.println(m);
            System.out.println("--mouse clicked");
            System.out.println(event.MOUSE_CLICKED);
            //code to create , display, popup
            }

            private UIComponent ImageButton(UIComponent parent){
            //I have changed the following line..
            methodExpression = elFactory.createMethodExpression( elContext,"#{pageFlowScope.pinint.handleImagePress}",Object.class,new Class[] {MouseEvent.class});
            }

            But it complains java.lang.IllegalArgumentException: argument type mismatch, when I click on the button.

            Please let me know of a work around with this issue.