Action listener in different class

Hi
I now have a class called Gui and a class called Listener.
The gui contains
public class Gui implements ActionListener
public void actionPerformed(ActionEvent e) { }the Listener contains
public class Listener extends gui implements ActionListener
public void actionPerformed(ActionEvent e)
{ System.out.println("test");     }The problem i have is how to destinct from which button is pressed or which comboBoxItem is pressed?
when i do :
if((e.getSource()).equals(btn1))I get a nullPointerException.
btn1 is defined to be protected in the class gui and is implemented:
btn.addActionListener(al);
where al is Listener al = new Listener(); created in the gui constructer.
Anyone that could help me out with how to determind which button is pressed?
Thanks

Re: readability - I completely agree that this is a very important issue and I conceded a wee hip-and-yip-yip hooray to your tutor /instructor. From what I read on these boards, it is something of a breath of frsh air to hear of such enlightened teaching - however ...
I don't see an argument here. I agree that in a big GUI build that naming your GUI something like;-
public class MyMainGUI extends JFrame implements ActionListener{
... is a bit ugly, however IMO:-
class ButtonListener implements ActionListener{
... is highly readable and clear
My personal preference is then to do this;-
class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent ae){
String action = ae.getActionCommand();
if(action.equals("blah")) doThis();
if(action.equals("blahBlah")) doThat();
... where doThis(); and doThat(); are method calls, ie: outside the CustomListenerClass - this maintains the structure and clarity. The problem with 'external classes' is that you often need to pass on variables in the constructor and sometimes you cannot access (or change) the variables in the MainGUI class without making variables and /or getter & setter methods static, which can be something of a counterflow to good OOP design.

Similar Messages

  • Calling an action from a different controller class with an input form

    I have a Controller class declared as follows...
    public class Controller extends PageFlowController
    This class is not in a package. Inside this Controller class, I have a form class that is used as input for an Action method.
    public static class OrderDetailsForm extends FormData
    I also have another Controller class that exists in a subdirectory (and consequently has a package name)..
    package createOrder;
    class CreateOrderController extends PageFlowController
    From an Action within this Controller class, I want to forward to an Action in the first Controller class. I need to get access to the OrderDetailsForm class to do this, but I don't know how to declare a variable of the OrderDetailsForm class. I tried to do this...
    Controller.OrderDetailsForm myForm;
    But the compiler doesn't accept this. My question is what is the class name that I should be specifying to create an instance of OrderDetailsForm that lives in the Controller class that doesn't live inside a package?

    Do you know how to create an object of a class in some other class? The code you wrote seems you dont have basic sense of what is a object and class. Where did you create the object of your People class in your animal class? Create the object of people class within the animal class like:
    public class Animals {
        People people;
        public Televoting() {
        public void showAnimals() {
            people = new People(); // This is called the object creation by calling the constructor of the People 
                                              // class. Now you can access all the methods and variables of your people
                                              // class through the people object.
            System.out.println(people.peoples[0] + " is not an animal, but a person.") // Notice the difference.
    }I am sorry to say that you are not a good student and learner.
    Shan.

  • Is there a way to have the same action listener for few buttons?

    guys, lets say i have button1, button2 and button3
    how do i add the same action listener for 3 of them. doing 3 different action listener is very tedius! my assignment have almots 100 buttons but I need their action listener to be the same.

    Hi,
    Your class needs an action listener, so add implements ActionListener to you class creation string.
    Then on each button set an action command;
    button1.setActionCommand(BUTTON1);Now add an listener;
    buttons1.addActionListener(this);Finally create a method to perform a task
    public void actionPerformed(ActionEvent e)
       if (e.getActionCommand().equals(BUTTON1))
           xxxx   
      }This should do the trick.
    adelebt

  • Best way to implement an Action Listener

    I have multiple anonymous classes for each button in my particular JPanel, this seems very... large and I am sure it is using a large amount of memory. Is there a better way to implement several action listeners to all these buttons so that they will still do their origional function but cut down on all the anonymous classes.

    Actually nothing of the sort. There is too much information to be able to be placed nicely on the Panel, so I have many buttons that open dialog boxes where the information is placed, buttons that perform specified tasks (adding, updating, loading, deleting, clearing all fields) on the database, and others, there is also action listeners on the jspinners comboboxes and others.
    Actually, I take back hundred, I recently extended JPanel to do my editing panels to go into my JTabbedPane cutting down on the line count in the FrameMain class (over 8K lines before the conversion) So there is only about 20 to 25 total action listeners per extended JPanel, instead of 150 or so declared in one frame.
    The biggest concern here is memory usage, as of right now it uses a ton, and by searching and reading, I belive its all the action listeners (which at the time I thought you had to have a brand new one every time you wanted it to do something different).
    Going back to the one action listener with the if/else statements obviously performace may be lost, but what is the ratio to performance lost to memory gain. Will the speed increase be negligable compared to the amount of memory usage that will go down?

  • Add action listener to an image....

    Hello there,
    I was wondering is it possible to add action listener to an image to connected back to a different page....
    for example if i have this code:
    ImageComponent displayFrame = new ImageComponent();
    add(displayFrame,"West");
    displayFrame.setBounds( 90,100,52,58);
    in one of my frame calling an instance Image component...
    Your coorperation is greatly appreaciated,
    Thanks,
    -pal-

    Here are a couple of suggestions.
    First suggestion is to use java.awt.CardLayout. This sets up a series of "cards" where only one is visible at a time.
            ActionListener buttonListener = new ButtonListener();
            JButton mainButton = new JButton("Forward");
            mainButton.addActionListener(buttonListener);
            JButton subButton = new JButton("Back");
            subButton.addActionListener(buttonListener);
            menuLayout = new java.awt.CardLayout();
            menuPanel = new JPanel(menuLayout);
            menuPanel.add("Main", mainPanel);
            menuPanel.add("Sub", subPanel);
        class ButtonListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
                String cmd = e.getActionCommand();
                if (cmd.equals("Forward")) {
                    menuLayout.show(menuPanel, "Sub");
                } else if (cmd.equals("Back")) {
                    menuLayout.show(menuPanel, "Main");
        }The other suggestion would be to use javax.swing.JDialog. That might be a little cleaner because it could be set up modal. It depends on what your menus look like. Check out this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html

  • How to use the different class for each screen as well as function.

    Hi Experts,
    How to use the different class for each screen as well as function.
    With BestRegards,
    M.Thippa Reddy.

    Hi ThippaReddy,
    see this sample code
    Public Class ClsMenInBlack
    #Region "Declarations"
        'Class objects
        'UI and Di objects
        Dim objForm As SAPbouiCOM.Form
        'Variables
        Dim strQuery As String
    #End Region
    #Region "Methods"
        Private Function GeRate() As Double
                Return Double
        End Function
    #End Region
    Public Sub SBO_Appln_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean)
            If pVal.BeforeAction = True Then
                If pVal.MenuUID = "ENV_Menu_MIB" Then
                End If
            Else ' Before Action False
                End If
        End Sub
    #End Region
    End Class
    End Class
    Rgds
    Micheal
    Vasu Anna Regional Feeling a???? Just Kidding
    Edited by: micheal willis on Jul 27, 2009 5:49 PM
    Edited by: micheal willis on Jul 27, 2009 5:50 PM

  • Transaction Posting Confirmation Message and Action Listener behaviour

    Hi, I have a scenario that a user is Posting a Transaction and when he press the “Post” Button a, confirmation dialog box should popup asking “Do you really want to Post the record ?”. If the user press “Yes” the record is further process and If the user press “No” then the transaction should not proceed.
    I have implemented the main screen(PostTransaction.java) and the popup confirmation window(ConfirmationWindow.java)
    Question 1 ) Why the code is not stoping in the Post Button Action listener as in JOptionPane, then how do i know that the user has selected "Yes" or "No" ?
    Question 2) Do I have to write the code for posting of a Transaction(postTransaction() method) in the “ConfirmationWindow”? or it should be in “PostTransaction”.
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.application.Application;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.GridPane;
    import javafx.stage.Stage;
    public class PostTransaction extends Application{
           public void start(final Stage stage) throws Exception {
                  Group root = new Group();
                  Scene scene = new Scene(root, 300,300);
                  stage.setScene(scene);
                  stage.setTitle("Transaction Post Screen");
                  GridPane gp = new GridPane();
                  Label lblName = new Label("Name");
                  Label lblAmount = new Label("Amount");
                  TextField txtName = new TextField();
                  TextField txtAmount = new TextField();
                  Button btnPost = new Button("Post Record");
                  gp.add(lblName, 1, 1);
                  gp.add(lblAmount, 1, 2);
                  gp.add(txtName, 2, 1);
                  gp.add(txtAmount, 2, 2);
                  gp.add(btnPost, 2, 3);
                  btnPost.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent arg0) {
                             //The code does not stop here as in JOptionPane, then how do i know that the user has selected "Yes" or "No" ??
                             boolean popupResult = ConfirmationWindow.confirmTranactionPosting(stage, "Please Confirm");
                             if(popupResult==true){
                                  //This line is printed before the user selects yes or no
                                  System.out.println("Proceeding with Tranaction Posting");
                                  //postTransaction();
                             if(popupResult==false){
                                  //This line is printed before the user selects yes or no
                                  System.out.println("Do not Proceed with Tranaction Posting");
                 root.getChildren().add(gp);
                stage.show();
                public static void main(String[] args) {
                  launch(args);
              private void postTransaction(){
                   //write the code for posting here
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.HBox;
    import javafx.stage.Modality;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    public class ConfirmationWindow extends Stage {
         Stage owner;
         Stage stage;
         BorderPane root;
         static boolean postStatus = false;
      public ConfirmationWindow( Stage owner, String title){
        root = new BorderPane();
        stage = this;
        this.owner = owner;
        initModality( Modality.APPLICATION_MODAL );
        initOwner( owner );
        initStyle( StageStyle.UTILITY );
        setTitle( title );
        setContents();
      public void setContents(){
        Scene scene = new Scene(root,250,150);
        setScene(scene);
        Group groupInDialog = new Group();
        groupInDialog.getChildren().add( new Label("Do you really want to Post this record ?") );
        root.setCenter( groupInDialog );
        Button yes = new Button( "Yes" );
        yes.setOnAction(new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent e) {
                   postStatus =true;
                   stage.close(); // Close the pop up. Transfer control to PostTransaction.java and execute the PostTransaction() method.
        Button no  = new Button( "No" );
        no.setOnAction(new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent e) {
                   postStatus =false;
                   stage.close(); // Close the pop up only
        HBox buttonPane = new HBox();
        buttonPane.setSpacing(10);
        buttonPane.getChildren().addAll(yes,no);
        root.setBottom(buttonPane);
        stage.show();
      public static boolean confirmTranactionPosting(Stage owner, String title) {
           new ConfirmationWindow(owner, title);
           return postStatus;
    }

    The MII Message listener is a queue. But when I understand you correctly, you do not want to process the messages immediately after arriving in the Listener.
    Maybe the categorization of messages is an option for you (see [Sap Help: Processing Rule Editor - Category|http://help.sap.com/saphelp_mii121/helpdata/en/43/e80b59ad40719ae10000000a1553f6/frameset.htm]. You can enter a category for the control recipe messages. The messages will then be placed in the Listener queue. You can use the [Message Services|http://help.sap.com/saphelp_mii121/helpdata/en/43/e80b59ad40719ae10000000a1553f6/frameset.htm] actions to read the categorized messages and process them as you need.
    In addition to Manoj, you may also use the [Queueing actions|http://help.sap.com/saphelp_mii121/helpdata/en/43/e80b59ad40719ae10000000a1553f6/frameset.htm] of MII, where you can queue xml contents.
    Hope this helps.
    Michael

  • Issue with setting an Action Listener for a Command Button

    Hi all,
    I'm trying to set an action listener for a CoreCommanButton in a backing bean. Here's my code:
         CoreCommandButton editBtn = new CoreCommandButton();
              MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{backBean.doButtonAct}",null);
              editBtn.setActionListener(mb);
    //Action listener method
         public void doButtonAct(ActionEvent actionEvent)
    I keep getting a javax.faces.el.MethodNotFoundException error. However when I remove the ActionEvent parameter in doButtonAct(), I get a wrong number of arguments error.
    So i'm guessing there is something wrong with the parameters i accept in my action listener method. what can be causing this issue?
    Cheers.

    I figured this out.
    Since doButtonAct() requires an ActionEvent object as a parameter, i needed to define the parameter type when I create the method binding.
    Solution:
         Class argsString[] = new Class[] { ActionEvent.class };
              MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{backBean.doButtonAct}",argsString);

  • Calling action listener for a BUTTON component in java bean page

    Hi,
    I have made it like this.
    public void handleButtonPressed(ActionEvent event){
    System.out.println("success!!!!!");
    //code for calling actionlistener
    FacesContext fctx = FacesContext.getCurrentInstance();
    ELContext elctx = fctx.getELContext();
    Application application = fctx.getApplication();
    ExpressionFactory exprFactory = application.getExpressionFactory();
    MethodExpression methodExpr = null;
    methodExpr = exprFactory.createMethodExpression(elctx, "#{exbean.handleButtonPressed}",null,new Class[] { ActionEvent.class });
    MethodExpressionActionListener actionListener = null;
    actionListener = new MethodExpressionActionListener(methodExpr);
    button.addActionListener(actionListener);
    Even after making the listener Function as Void wHen i click the button i m getting the error saying."ARGUMENTS MISMATCH,ADF_FACES60097"??
    can you help me out?
    and in the msg log i m getting this
    "SkinFactoryImpl> <getSkin> Cannot find a skin that matches family portal and version v1.1. We will use the skin portal.desktop.
    <MethodExpressionActionListener> <processAction> Received 'javax.el.PropertyNotFoundException' when invoking action listener '#{exbean.handleButtonPressed}' for component 'null'
    <MethodExpressionActionListener> <processAction> javax.el.PropertyNotFoundException: Target Unreachable, identifier 'custombean' resolved to null"
    I Have tried with this giving Void TYPE as an argument
    methodExpr = exprFactory.createMethodExpression(elctx, "#{exbean.handleButtonPressed},Void.TYPE,new Class[] { ActionEvent.class });
    I M getting the same error.
    Edited by: chaya on Dec 22, 2011 2:47 PM

    yeah but i m creating button itself dynamically by java code....
    //code
    UIComponent button;
    button = findComponentInRoot("cb1");
    RichPanelGroupLayout pgl;
    pgl = (RichPanelGroupLayout)button.getParent();
    List<UIComponent> children;
    children = pgl.getChildren();
    RichPanelGroupLayout pgll;
    pgll = new RichPanelGroupLayout();
    RichInputText it;
    it = new RichInputText();
    it.setLabel("New textbox " + (children.size()));
    RichCommandButton but = new RichCommandButton();
    but.setPartialSubmit(true);
    but.setText("Delete");
    /*calling actionevent*/
    FacesContext fctx = FacesContext.getCurrentInstance();
    ELContext elctx = fctx.getELContext();
    Application application = fctx.getApplication();
    ExpressionFactory exprFactory = application.getExpressionFactory();
    MethodExpression methodExpr = null;
    methodExpr = exprFactory.createMethodExpression( elctx,"#{inbean.actionPerformed}",null, new Class[] {ActionEvent.class});
    MethodExpressionActionListener actionListener = null;
    actionListener = new MethodExpressionActionListener(methodExpr);
    but.addActionListener(actionListener);
    /*end of call*/
    children.add(pgll);
    children.add(it);
    children.add(but);
    AdfFacesContext.getCurrentInstance().addPartialTarget(pgl);
    //code to call method
    public void actionPerformed(ActionEvent event) {
    System.out.println("entered sec bean");
    return " ";}
    this way i m trying to create a button programatically and tryin to add actionlistener which is not working.
    the actionlistener is throwing error.... with the line
    methodExpr = exprFactory.createMethodExpression( elctx,"#{inbean.actionPerformed}",null, new Class[] {ActionEvent.class});

  • Problem with action listener

    hello
    the problem in my code is that i defined
    actionlistener for a button but it does not
    do what it should do . it throws an error in the console
    and i think my code is 100% correct what is the problem
    please help me this is the codewith
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class Library extends JFrame implements ActionListener     {
         private JMenuBar jmb      = new JMenuBar();
         private JMenu books      = new JMenu("Books",true);
         private JMenu members      = new JMenu("Members",true);
         private JMenu loans      = new JMenu("Loans",true);
         private JMenuItem addNb = new JMenuItem("Add New Book");
         private JMenuItem listB = new JMenuItem("List All Books");
         private JMenuItem listAb = new JMenuItem("List Available Books");
         private JMenuItem listBb = new JMenuItem("List Borrowed Books");
         private JMenuItem addNm = new JMenuItem("Add New Member");
         private JMenuItem removeM = new JMenuItem("Remove a Member");
         private JMenuItem listAm = new JMenuItem("List All Members");
         private JMenuItem loanB = new JMenuItem("Loan A Book");
         private JMenuItem returnB = new JMenuItem("Return A Book");
         private JTextField bNumber = new JTextField(14);
         private JTextField bAuthor = new JTextField(14);
         private JTextField bTitle = new JTextField(14);
         private JTextField mId = new JTextField(14);
         private JTextField mName = new JTextField(14);
         private JTextField idB = new JTextField(14);
         private JTextField nBToB = new JTextField(14);
         private JTextField nBTor = new JTextField(14);
         private JTextArea dispaly = new JTextArea();
         private JButton oKb1 = new JButton("OK");
         private JButton okb2 = new JButton("OK");
         private JButton cloaseb = new JButton("Close");
         private JButton oKm1 = new JButton("OK");
         private JButton oKm2 = new JButton("OK");
         private JButton cancelM = new JButton("Cancel");
         private JButton oKm3 = new JButton("OK");
         private JButton oKm4 = new JButton("OK");
         private JButton cancelM2 = new JButton("Cancel");
         private JButton oKl = new JButton("OK");
         private JButton oKr = new JButton("OK");
         private JButton yes = new JButton("Yes");
         private JButton no = new JButton("No");     
         private JLabel bN = new JLabel("Book Number");
         private JLabel bA = new JLabel("Book Author");
         private JLabel bT = new JLabel("Book Title");
         private JLabel iN          = new JLabel("ID Number");
         private JLabel mN          = new JLabel("Member's Name");
         private JLabel     iNb          = new JLabel("ID number of the borrower");
         private JLabel nBb          = new JLabel("Number of the books to borrow");
         private JLabel nBr          = new JLabel("Number of the books to return");
         private JLabel mIdl     = new JLabel("ID number of the stuednt");
         private JPanel tempoIPanel= new JPanel(new FlowLayout());
         Container cp;
         JFrame mainFrame;
         JInternalFrame tempoI;
    Library()     {
         //LibraryClass lClass = new LibraryClass();/*
         mainFrame = new JFrame();
         mainFrame.setJMenuBar(jmb);
         mainFrame.setSize(800,550);
         mainFrame.getContentPane().setLayout(new FlowLayout());
         jmb.add(books);
         jmb.add(members);
         jmb.add(loans);
         books.add(addNb);
         addNb.addActionListener(this);
         books.add(listB);
         listB.addActionListener(this);
         books.add(listAb);
         listAb.addActionListener(this);
         books.add(listBb);
         listBb.addActionListener(this);
         members.add(addNm);
         addNm.addActionListener(this);
         members.add(removeM);
         removeM.addActionListener(this);
         members.add(listAm);
         listAm.addActionListener(this);
         loans.add(loanB);
         loanB.addActionListener(this);
         loans.add(returnB);
         returnB.addActionListener(this);
         //actions listeners
         oKb1.addActionListener(this);
         mainFrame.setVisible(true);
    public void actionPerformed(ActionEvent ae)     {
         if(ae.getSource() == addNb)     {
              tempoI = new JInternalFrame("Add new Book",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(bN);
              tempoI.getContentPane().add(bNumber);
              tempoI.getContentPane().add(bA);
              tempoI.getContentPane().add(bAuthor);
              tempoI.getContentPane().add(bT);
              tempoI.getContentPane().add(bTitle);
              tempoI.getContentPane().add(oKb1);//add action listener here
              tempoI.setVisible(true);
         if(ae.getSource() == listB)     {
              //LibraryClass.listBooks();
         if(ae.getSource() == listAb){}
         if(ae.getSource() == listBb){}
         if(ae.getSource() == addNm)     {
              tempoI = new JInternalFrame("Add new Member",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(iN);
              tempoI.getContentPane().add(mId);
              tempoI.getContentPane().add(mN);
              tempoI.getContentPane().add(mName);
              tempoI.getContentPane().add(oKm1);//add action listener
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == removeM)     {
              tempoI = new JInternalFrame("Rmove member",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(mIdl);
              tempoI.getContentPane().add(mId);
              tempoI.getContentPane().add(oKm2);//add action listener
              //LibraryClass.removeM(Double.parseDouble(mId.getText()));
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == listAm)     {
              //LibraryClass.listMembers();
         if(ae.getSource() == loanB)     {
              tempoI = new JInternalFrame("Loan book",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(iNb);
              tempoI.getContentPane().add(idB);
              tempoI.getContentPane().add(nBb);
              tempoI.getContentPane().add(nBToB);
              tempoI.getContentPane().add(oKl);
              //LibraryClass.borrowBook(Book bk,Member m);
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == returnB)     {
              tempoI = new JInternalFrame("Return Book",true,true);
              mainFrame.getContentPane().add(tempoI);
              tempoI.getContentPane().setLayout(new FlowLayout());
              tempoI.getContentPane().add(iNb);
              tempoI.getContentPane().add(idB);
              tempoI.getContentPane().add(nBr);
              tempoI.getContentPane().add(nBTor);
              tempoI.getContentPane().add(oKr);
              tempoI.getContentPane().setSize(400,300);
              tempoI.setVisible(true);
              //Book.addBook(bNumber.getText(),bAuthor.getText(),bTitle.getText());
    class ClubLibrarySystem     {
         public static void main(String[] args)     {
         new Library();
    }

    hello
    the problem in my code is that i defined
    actionlistener for a button but it does not
    do what it should do . it throws an error in the
    consoleWhat error?
    and i think my code is 100% correct what is theWell, but it isn't.
    Have you tried using a debugger?
    problem
    please help me this is the codewith
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class Library extends JFrame implements
    ActionListener     {
         private JMenuBar jmb      = new JMenuBar();
         private JMenu books      = new JMenu("Books",true);
    private JMenu members      = new
    JMenu("Members",true);
    private JMenu loans      = new
    JMenu("Loans",true);
    private JMenuItem addNb = new JMenuItem("Add New
    Book");
    private JMenuItem listB = new JMenuItem("List All
    Books");
    private JMenuItem listAb = new JMenuItem("List
    Available Books");
    private JMenuItem listBb = new JMenuItem("List
    Borrowed Books");
    private JMenuItem addNm = new JMenuItem("Add New
    Member");
    private JMenuItem removeM = new JMenuItem("Remove a
    Member");
    private JMenuItem listAm = new JMenuItem("List All
    Members");
    private JMenuItem loanB = new JMenuItem("Loan A
    Book");
    private JMenuItem returnB = new JMenuItem("Return A
    Book");
         private JTextField bNumber = new JTextField(14);
         private JTextField bAuthor = new JTextField(14);
         private JTextField bTitle = new JTextField(14);
         private JTextField mId = new JTextField(14);
         private JTextField mName = new JTextField(14);
         private JTextField idB = new JTextField(14);
         private JTextField nBToB = new JTextField(14);
         private JTextField nBTor = new JTextField(14);
         private JTextArea dispaly = new JTextArea();
         private JButton oKb1 = new JButton("OK");
         private JButton okb2 = new JButton("OK");
         private JButton cloaseb = new JButton("Close");
         private JButton oKm1 = new JButton("OK");
         private JButton oKm2 = new JButton("OK");
         private JButton cancelM = new JButton("Cancel");
         private JButton oKm3 = new JButton("OK");
         private JButton oKm4 = new JButton("OK");
         private JButton cancelM2 = new JButton("Cancel");
         private JButton oKl = new JButton("OK");
         private JButton oKr = new JButton("OK");
         private JButton yes = new JButton("Yes");
         private JButton no = new JButton("No");     
    private JLabel bN = new JLabel("Book
    Number");
    private JLabel bA = new JLabel("Book
    Author");
    private JLabel bT = new JLabel("Book
    Title");
         private JLabel iN          = new JLabel("ID Number");
    private JLabel mN          = new JLabel("Member's
    Name");
    private JLabel     iNb          = new JLabel("ID number of the
    borrower");
    private JLabel nBb          = new JLabel("Number of the
    books to borrow");
    private JLabel nBr          = new JLabel("Number of the
    books to return");
    private JLabel mIdl     = new JLabel("ID number of
    the stuednt");
    private JPanel tempoIPanel= new JPanel(new
    FlowLayout());
         Container cp;
         JFrame mainFrame;
         JInternalFrame tempoI;
    Library()     {
         //LibraryClass lClass = new LibraryClass();/*
         mainFrame = new JFrame();
         mainFrame.setJMenuBar(jmb);
         mainFrame.setSize(800,550);
    mainFrame.getContentPane().setLayout(new
    FlowLayout());
         jmb.add(books);
         jmb.add(members);
         jmb.add(loans);
         books.add(addNb);
         addNb.addActionListener(this);
         books.add(listB);
         listB.addActionListener(this);
         books.add(listAb);
         listAb.addActionListener(this);
         books.add(listBb);
         listBb.addActionListener(this);
         members.add(addNm);
         addNm.addActionListener(this);
         members.add(removeM);
         removeM.addActionListener(this);
         members.add(listAm);
         listAm.addActionListener(this);
         loans.add(loanB);
         loanB.addActionListener(this);
         loans.add(returnB);
         returnB.addActionListener(this);
         //actions listeners
         oKb1.addActionListener(this);
         mainFrame.setVisible(true);
    public void actionPerformed(ActionEvent ae)     {
         if(ae.getSource() == addNb)     {
    tempoI = new JInternalFrame("Add new
    w Book",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(bN);
              tempoI.getContentPane().add(bNumber);
              tempoI.getContentPane().add(bA);
              tempoI.getContentPane().add(bAuthor);
              tempoI.getContentPane().add(bT);
              tempoI.getContentPane().add(bTitle);
    tempoI.getContentPane().add(oKb1);//add action
    n listener here
              tempoI.setVisible(true);
         if(ae.getSource() == listB)     {
              //LibraryClass.listBooks();
         if(ae.getSource() == listAb){}
         if(ae.getSource() == listBb){}
         if(ae.getSource() == addNm)     {
    tempoI = new JInternalFrame("Add new
    w Member",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(iN);
              tempoI.getContentPane().add(mId);
              tempoI.getContentPane().add(mN);
              tempoI.getContentPane().add(mName);
    tempoI.getContentPane().add(oKm1);//add action
    n listener
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == removeM)     {
    tempoI = new JInternalFrame("Rmove
    e member",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(mIdl);
              tempoI.getContentPane().add(mId);
    tempoI.getContentPane().add(oKm2);//add action
    n listener
              //LibraryClass.removeM(Double.parseDouble(mId.getText
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == listAm)     {
              //LibraryClass.listMembers();
         if(ae.getSource() == loanB)     {
              tempoI = new JInternalFrame("Loan book",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(iNb);
              tempoI.getContentPane().add(idB);
              tempoI.getContentPane().add(nBb);
              tempoI.getContentPane().add(nBToB);
              tempoI.getContentPane().add(oKl);
              //LibraryClass.borrowBook(Book bk,Member m);
              tempoI.getContentPane().setSize(300,400);
              tempoI.setVisible(true);
         if(ae.getSource() == returnB)     {
    tempoI = new JInternalFrame("Return
    n Book",true,true);
              mainFrame.getContentPane().add(tempoI);
    tempoI.getContentPane().setLayout(new
    w FlowLayout());
              tempoI.getContentPane().add(iNb);
              tempoI.getContentPane().add(idB);
              tempoI.getContentPane().add(nBr);
              tempoI.getContentPane().add(nBTor);
              tempoI.getContentPane().add(oKr);
              tempoI.getContentPane().setSize(400,300);
              tempoI.setVisible(true);
              //Book.addBook(bNumber.getText(),bAuthor.getText(),bT
    tle.getText());
    class ClubLibrarySystem     {
         public static void main(String[] args)     {
         new Library();

  • Action Listener Method called multiple times

    I have a page (fragment .jsff), containing a simple input text and a button called "search". When I click on "Search" the action listener is triggered multiple times. (The results are displayed in a table inside a panel collection).
    The results are actually coming back ok.
    When I debug the code, I can see the action listener method called twice.
    Do you know why is that?
    What should I be taking care of?
    This is my code :
    *** Fragment ****
    <af:commandButton text="#{identityBundle.search_label}" id="cb1"
    actionListener="#{UserDetailsBean.searchUsersListener}"
    disabled="#{!bindings.searchUsers.enabled}"/>
    *** Managed bean ***
    public void searchUsersListener(ActionEvent actionEvent) {
    // Add event code here...
    DCBindingContainer bindings = (DCBindingContainer)getBindings();
    DCIteratorBinding iter = bindings.findIteratorBinding("userIterator");
    DCDataRow row = (DCDataRow)iter.getCurrentRow();
    User user = (User)row.getDataProvider();
    boolean isSearchCriteriaPresent = false;
    if(user != null){
    String fn = user.getFirstname();
    if(fn != null && !fn.trim().equals("")){
    isSearchCriteriaPresent = true;
    user.setLastname(fn);
    user.setNonMTUserLogin(fn);
    try {
    Map <Object, Object> userMap = PropertyUtils.describe(user);
    for(Map.Entry<Object, Object> entry: userMap.entrySet()){
    if(entry.getKey() != null && entry.getValue() != null && !entry.getKey().toString().equalsIgnoreCase("class")){
    isSearchCriteriaPresent = true;
    break;
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    } catch (InvocationTargetException e) {
    e.printStackTrace();
    } catch (NoSuchMethodException e) {
    e.printStackTrace();
    if(!isSearchCriteriaPresent){
    user.setFirstname("*");
    OperationBinding opBinding = (OperationBinding)bindings.getOperationBinding("searchUsers");
    opBinding.getParamsMap().put("user", user);
    opBinding.execute();
    AdfFacesContext adfFacesCtx = AdfFacesContext.getCurrentInstance();
    Map<String, Object> scopePageFlowScopeVar= adfFacesCtx.getPageFlowScope();
    scopePageFlowScopeVar.put("userSearchCriteria", user);
    ADFContext adfCtx = ADFContext.getCurrent();
    Map sessionScope = adfCtx.getSessionScope();
    sessionScope.put("userSearchCriteria", user);
    setUserSearchCriteria(user);
    if(selectedUserID != null){
    selectedUserID.setValue(null);
    RichTable table = getUserResultsTable();
    DCIteratorBinding searchUsersIterator = (DCIteratorBinding)bindings.get("searchUsersIterator");
    Row[] rows = searchUsersIterator.getAllRowsInRange();
    if(rows.length > 0){
    RowKeySetImpl rks = new RowKeySetImpl();
    ArrayList keyList = new ArrayList();
    keyList.add(rows[0].getKey());
    rks.add(keyList);
    table.setSelectedRowKeys(rks);
    table.setDisplayRowKey(keyList);
    refreshState(table);
    if(!isSearchCriteriaPresent){
    user.setFirstname(null);
    else{
    deleteUserButton.setDisabled(true);
    resetPasswordButton.setDisabled(true);
    enableUserButton.setDisabled(true);
    disableUserButton.setDisabled(true);
    Thanks in advance for your help

    Hi,
    Can you try this?
    1. set partialSubmit=true for the "search" button
    2. set "search" button id as partialTrigger in your result table
    -Prasad

  • How to create a single action listener for a group of buttons

    hi there.. i am new at java and i have a problem with my applet..
    i am doing a virtual ticket programme..
    i have a tab that says books seats.. in the tab, i am suppose to create 50 buttons.
    i have done that already by using for (int i=1; i<=10;i++) 5 times for 50 buttons.
    but i do not know how to set an actionlistener in the for loop for each of these buttons..
    For example, if the user were to chose seat "no3" , a text area(already created) below will show something like "no3" and so on..
    how do i bind these buttons into one single action listener so i do not have to create 50 actionlisteners and buttons individually..
    appreciate the help..

    You're killing me.
    class MyFrame extends JFrame implements ActionListener
         JTextArea myTextArea = new JTextArea();
         JButton myButton = new JButton("My Button");
         JButton otherButton = new JButton("Other Button");
         MyFrame()
              super();
              myButton.addActionListener(this);
              otherButton.addActionListener(this);
              setLayout(new FlowLayout());
              add(myButton);
              add(otherButton);
              add(myTextArea);
         public void actionPerformed(ActionEvent e)
              Object source = e.getSource();
              if(source == myButton)
                   myTextArea.append("My Button Pressed\n");
              else if(source == otherButton)
                   myTextArea.append("Other Button Pressed\n");
    }

  • Listeners in a different class??

    Hi ,
    Is it possible to listen the events of "Class A" in "Class B"?? I have certain events that raise in "Class A". I need to listen this in "Class B". I believe there is a descent way of doing this in Swing. Can anyone share ??
    Thanks in Advance..
    regards
    Rajesh rapaka.

    I guess u are talking about something like this :
    AbstractButton button = new JButton("OK");
        button.addActionListener(new MyActionListener());
        public class MyActionListener implements ActionListener {
            public void actionPerformed(ActionEvent evt) {
                // Determine which abstract button fired the event.
                AbstractButton button = (AbstractButton)evt.getSource();
        }But what I am looking for is something different. where the conditions are like this :
    example:
    public class Frm extends JFrame{
    public Frm(){
    ToolBar mb = new ToolBar();
    add(mb);
    }Class ToolBar:
    public class ToolBar extends JToolBar implements ActionListener{
    public ToolBar(){
    JButton jb = new JButton("tstButton");
    jb.addActionListener(this);
    public void actionPerformed(ActionEvent e){
    System.out.Println("event raised");
    }The ToolBar class is initialised and added on the frame. Which has buttons on it which raise events. How can I get these raised events in Frm class?? I want to have an ActionListener in Frm class that can listen to events raised even in MenuBar.
    is this possible ? and how ?
    thank for ur time in advance....
    regs,
    Rajesh rapaka.

  • Accessing a different class using ActionPerformed

    hi
    im trying to access a method in a different class using
    public void actionPerformed (ActionEvent e) {
              if(e.getSource() == AuthorCombo) {
                   ComboAction();
              else if(e.getSource() == SearchButton){
                        SearchSystem();
    }and then using
    public class Book extends ViewPanel{
    public void SearchSystem(){// this is used to get the information from
                      //the combo boxs whixh can latter show
                      //the data in the text area
    tempBookNoList.clear();
              for(int a=0; a<AuthorList.size(); a++) {
                                  if(((String)AuthorCombo.getSelectedItem()
                                  ==AuthorList.get(a))
                                  &&((String)BookCombo.getSelectedItem()
                                  ==BookList.get(a))) {
                                       tempBookNoList.add((String)BookNoList.get(a));
                        String result = (String)tempBookNoList.get(a);
                        InfoArea.setText ((String)tempBookNoList.get(a));
    }          }//End neither random situation.to manipulate some data within the other class
    i keep getting the error
    .\ViewPanel.java:314: cannot resolve symbol
    symbol : method SearchSystem ()
    location: class ViewPanel
                        SearchSystem();
    ^
    1 error
    can anyone help me spot the problem

    in that case i do not know what could be the cause in this program
    the only area i think it could be is when the SearchSystem method in the Book class gets using the Action Performed method in the Viewpanel method, shown below
    public class Book extends ViewPanel{
    public void SearchSystem(){// this is used to get the information from
                      //the combo boxs whixh can latter show
                      //the data in the text area
              for(int a=0; a<AuthorList.size(); a++) {
                                  if(((String)AuthorCombo.getSelectedItem()
                                  ==AuthorList.get(a))
                                  &&((String)BookCombo.getSelectedItem()
                                  ==BookList.get(a))) {
                                  InfoArea.setText((String)BookNoList.get(a));
                   }which is called using
    public void actionPerformed (ActionEvent e) {
              if(e.getSource() == AuthorCombo) {
                   ComboAction();
              else if(e.getSource() == SearchButton){
                        theBook.SearchSystem();
    }but i cant see this being a problem as it all compiles

  • Custom button with action listener - will not invoke action listener

    Hi
    For whatever reason, I cannot find a concise example of a simple custom component that can invoke an action listener. The tutorials I've read so far either ignore this fundamental topic or only make the slightest make reference to it.
    The best I have come up with - in terms of a simple prototype is below... but, the action listener is never invoked.... Can someone tell me what I am missing (full code below). Hopefully, what is missing or incorrect will be obvious to you JSF experts out there.
    Thanks for any help!!
    -f
    tld
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
      <tlib-version>0.01</tlib-version>
      <jsp-version>1.2</jsp-version>
      <short-name>jsfcustomcomponent</short-name>
      <uri>http://jsfcustomcomponent/</uri>
      <description><![CDATA[jsf custom component tags]]>  </description>
      <tag>
        <name>specialBtnTag</name>
        <tag-class>jsfcustomcomponent.SpecialBtnTag</tag-class>
        <attribute>
          <name>value</name>
          <required>true</required>
          <rtexprvalue>true</rtexprvalue>
          <description><![CDATA[button value]]></description>
        </attribute>
        <attribute>
          <name>actionListener</name>
          <required>true</required>
          <rtexprvalue>true</rtexprvalue>
          <description><![CDATA[action listener]]> </description>
        </attribute>
      </tag>
    </taglib>
    SpecialBtnComponent
    package jsfcustomcomponent;
    import javax.faces.component.*;
    import javax.faces.context.*;
    import javax.faces.el.*;
    import javax.faces.event.*;
    public class SpecialBtnComponent
        extends UIComponentBase implements ActionSource
        public static final String COMPONENT_TYPE = "SpecialBtnComponent";
        public static final String RENDERER_TYPE = "SpecialBtnRenderer";
        public String getFamily()
            return COMPONENT_TYPE;
        public SpecialBtnComponent()
            super();
            setRendererType(SpecialBtnComponent.RENDERER_TYPE);
        private String value;
        public void setValue(String value, FacesContext facesContext)
            this.value = value;
        public String getValue()
            if (null != value)
                return value;
            ValueBinding _vb = getValueBinding("value");
            if (_vb != null)
                return (String) _vb.getValue(getFacesContext());
            else
                return null;
        private MethodBinding action = null;
        public MethodBinding getAction()
            return action;
        public void setAction(MethodBinding methodBinding)
            this.action = action;
        private MethodBinding actionListener = null;
        public MethodBinding getActionListener()
            return (this.actionListener);
        public void setActionListener(MethodBinding methodBinding)
            this.actionListener = actionListener;
        public boolean isImmediate()
            return false;
        public void setImmediate(boolean _boolean)
            //this.immediate = immediate;
        public void addActionListener(ActionListener actionListener)
            addFacesListener(actionListener);
        public ActionListener[] getActionListeners()
            return (ActionListener[]) getFacesListeners(ActionListener.class);
        public void removeActionListener(ActionListener actionListener)
            removeFacesListener(actionListener);
        public Object saveState(FacesContext context)
            Object values[] = new Object[5];
            values[0] = super.saveState(context);
            values[1] = value;
            values[2] = saveAttachedState(context, action);
            values[3] = saveAttachedState(context, actionListener);
            return ( (Object) (values));
        public void restoreState(FacesContext context, Object state)
            Object values[] = (Object[]) state;
            super.restoreState(context, values[0]);
            value = (String) values[1];
            action = (MethodBinding) restoreAttachedState(context, values[2]);
            actionListener = (MethodBinding) restoreAttachedState(context, values[3]);
        public void broadcast(FacesEvent event) throws AbortProcessingException
            super.broadcast(event);
            if (event instanceof ActionEvent)
                FacesContext context = getFacesContext();
                MethodBinding mb = getActionListener();
                if (mb != null)
                    mb.invoke(context, new Object[]
                              {event});
                ActionListener listener = context.getApplication().getActionListener();
                if (listener != null)
                    listener.processAction( (ActionEvent) event);
        public void queueEvent(FacesEvent e)
            if (e instanceof ActionEvent)
                if (isImmediate())
                    e.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
                else
                    e.setPhaseId(PhaseId.INVOKE_APPLICATION);
            super.queueEvent(e);
    SpecialBtnRenderer
    package jsfcustomcomponent;
    import java.util.*;
    import javax.faces.component.*;
    import javax.faces.context.*;
    import javax.faces.event.*;
    import javax.faces.render.*;
    public class SpecialBtnRenderer
        extends Renderer
        String value;
        public SpecialBtnRenderer()
        public void decode(FacesContext context, UIComponent component)
            Map requestMap = context.getExternalContext().getRequestParameterMap();
            String clientId = component.getClientId(context);
            SpecialBtnComponent specialBtnComponent = (SpecialBtnComponent) component;
            String value = (String) requestMap.get(clientId);
            if (null != value)
                specialBtnComponent.setValue(value, context);
            ActionEvent actionEvent = new ActionEvent(specialBtnComponent);
            specialBtnComponent.queueEvent(actionEvent);
        public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException
            SpecialBtnComponent specialBtnComponent = (SpecialBtnComponent) component;
            ResponseWriter writer = context.getResponseWriter();
            String clientId = component.getClientId(context);
            value = (String) component.getAttributes().get("value");
            if (value == null)
                value = "defaultValue";
            buildSpecialBtn(writer, value, clientId, specialBtnComponent);
        private void buildSpecialBtn(ResponseWriter writer, String value, String clientId, SpecialBtnComponent component) throws java.io.IOException
            writer.startElement("table", component);
            writer.startElement("tbody", component);
            writer.startElement("tr", component);
            writer.startElement("td", component);
            value = String.valueOf(value);
            writer.startElement("input", component);
            writer.writeAttribute("type", "submit", null);
            writer.writeAttribute("name", clientId, "clientId");
            writer.writeAttribute("value", value, null);
            writer.endElement("input");
            writer.endElement("td");
            writer.endElement("tr");
            writer.endElement("tbody");
            writer.endElement("table");
    SpecialBtnTag
    package jsfcustomcomponent;
    import javax.faces.component.*;
    import javax.faces.el.*;
    import javax.faces.webapp.*;
    import com.sun.faces.util.*;
    public class SpecialBtnTag
        extends UIComponentTag
        public String value = null;
        public String actionListener = null;
        public String getComponentType()
            return SpecialBtnComponent.COMPONENT_TYPE;
        public String getRendererType()
            return SpecialBtnComponent.RENDERER_TYPE;
        protected void setProperties(UIComponent component)
            super.setProperties(component);
            if (! (component instanceof SpecialBtnComponent))
                throw new IllegalStateException("Component " + component.toString() +
                                                " not expected type.  Expected: jsfcustomcomponent.SpecialBtnComponent.  Perhaps you�re missing a tag?");
            SpecialBtnComponent specialBtnComponent = (SpecialBtnComponent) component;
            if (value != null)
                if (isValueReference(value))
                    ValueBinding vb = Util.getValueBinding(value);
                    specialBtnComponent.setValueBinding("value", vb);
                else
                    throw new IllegalStateException("The value for �value� must be a ValueBinding.");
            if (actionListener != null)
                if (isValueReference(actionListener))
                    ValueBinding vb = Util.getValueBinding(actionListener);
                    specialBtnComponent.setValueBinding("actionListener", vb);
                else
                    throw new IllegalStateException("The value for �actionListener� must be a ValueBinding.");
        public void release()
            super.release();
            value = null;
            actionListener = null;
        public void setValue(String value)
            this.value = value;
        public String getValue()
            return this.value;
        public void setActionListener(String actionListener)
            this.actionListener = actionListener;
        public String getActionListener()
            return this.actionListener;
    jsp1.jsp
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@taglib uri="http://jsfcustomcomponent/" prefix="j"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    <link rel="stylesheet" type="text/css" href="./stylesheet.css" title="Style">
    </head>
    <body>
    <f:view>
      <h:form id="form01">
        <h:outputText value="test special button with action listener"/>
        <j:specialBtnTag value="#{specialBtnBacking.specialBtnValue}" actionListener="#{specialBtnBacking.specialBtnActionListener}"/>
        <h:messages/>
        <h:outputText value="#{specialBtnBacking.outcome}"/>
      </h:form>
    </f:view>
    </body>
    </html>
    SpecialBtnBacking
    package specialbtn;
    import javax.faces.context.*;
    import javax.faces.event.*;
    public class SpecialBtnBacking
        private FacesContext context;
        public SpecialBtnBacking()
            this.setSpecialBtnValue("Special Button with action listener");
        private String specialBtnValue;
        public String getSpecialBtnValue()
            return this.specialBtnValue;
        public void setSpecialBtnValue(String specialBtnValue)
            this.specialBtnValue = specialBtnValue;
        private String outcome="actionlistener NOT invoked: click specialBtn above to test";
        public String getOutcome()
            return outcome;
        public void setOutcome(String outcome)
            this.outcome = outcome;
        public void specialBtnActionListener(ActionEvent evt)
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Jsp1Backing/specialBtnActionListener()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            this.outcome="***action listener invoked!!!***";
    faces-config.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config>
      <managed-bean>
        <managed-bean-name>specialBtnBacking</managed-bean-name>
        <managed-bean-class>specialbtn.SpecialBtnBacking</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
      </managed-bean>
      <component>
        <component-type>SpecialBtnComponent</component-type>
        <component-class>jsfcustomcomponent.SpecialBtnComponent</component-class>
        <component-extension>
          <renderer-type>SpecialBtnRenderer</renderer-type>
        </component-extension>
      </component>
      <render-kit>
        <renderer>
          <component-family>SpecialBtnComponent</component-family>
          <renderer-type>SpecialBtnRenderer</renderer-type>
          <renderer-class>jsfcustomcomponent.SpecialBtnRenderer</renderer-class>
        </renderer>
      </render-kit>
    </faces-config>
    web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
      <display-name>pagerWEB</display-name>
      <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
      </servlet-mapping>
      <jsp-config>
        <taglib>
          <taglib-uri>http://jsfcustomcomponent/</taglib-uri>
          <taglib-location>/WEB-INF/jsfcustomcomponent.tld</taglib-location>
        </taglib>
      </jsp-config>
      <servlet>
        <description>Added by JBuilder to compile JSPs with debug info</description>
        <servlet-name>debugjsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
          <param-name>classdebuginfo</param-name>
          <param-value>true</param-value>
        </init-param>
        <load-on-startup>3</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>debugjsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
      </servlet-mapping>
    </web-app>

    got it working....
    The changes were:
    in "SpecialBtnRenderer"...
    --new--
                        mb.invoke(context, new Object[1]);
    --old--
                        mb.invoke(context, new Object[0]);
    in "SpecialBtnTag"...
    --new--
    import javax.faces.event.ActionEvent;
    --new--
                    MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(specialBtnListener, new Class[]{ActionEvent.class});
    --old--
                    MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(specialBtnListener, null);
    -Below is the entire application, again -- for those (like myself) who need concrete examples...
    I hope this helps someone else! --f
    jsp1.jsp
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@taglib uri="http://jsfcustomcomponent/" prefix="j"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    <link rel="stylesheet" type="text/css" href="./stylesheet.css" title="Style">
    </head>
    <body>
    <f:view>
        <h:messages/>
      <h:form id="form01">
        <h:outputText value="test special button with action listener"/>
        <j:specialBtnTag value="#{specialBtnBacking.specialBtnValue}" specialBtnListener="#{specialBtnBacking.specialBtnActionListener}"/>
        <h:outputText value="#{specialBtnBacking.outcome}"/>
      </h:form>
    </f:view>
    </body>
    </html>
    SpecialBtnBacking
    package specialbtn;
    import javax.faces.context.*;
    import javax.faces.event.*;
    public class SpecialBtnBacking
        private FacesContext context;
        public SpecialBtnBacking()
            this.setSpecialBtnValue("Special Button with action listener");
        private String specialBtnValue;
        public String getSpecialBtnValue()
            return this.specialBtnValue;
        public void setSpecialBtnValue(String specialBtnValue)
            this.specialBtnValue = specialBtnValue;
        private String outcome = "actionlistener NOT invoked: click specialBtn above to test";
        public String getOutcome()
            return outcome;
        public void setOutcome(String outcome)
            this.outcome = outcome;
        public void specialBtnActionListener(ActionEvent evt)
            System.out.println("\n\n");
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Jsp1Backing/specialBtnActionListener()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Jsp1Backing/specialBtnActionListener()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Jsp1Backing/specialBtnActionListener()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Jsp1Backing/specialBtnActionListener()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Jsp1Backing/specialBtnActionListener()!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n");
            this.outcome = "***action listener invoked!!!***";
    jsfcustomcomponent.tld
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
      <tlib-version>0.01</tlib-version>
      <jsp-version>1.2</jsp-version>
      <short-name>jsfcustomcomponent</short-name>
      <uri>http://jsfcustomcomponent/</uri>
      <description><![CDATA[jsf custom component tags]]>  </description>
      <tag>
        <name>specialBtnTag</name>
        <tag-class>jsfcustomcomponent.SpecialBtnTag</tag-class>
        <attribute>
          <name>value</name>
          <required>true</required>
          <rtexprvalue>true</rtexprvalue>
          <description><![CDATA[button value]]></description>
        </attribute>
        <attribute>
          <name>specialBtnListener</name>
          <required>true</required>
          <rtexprvalue>true</rtexprvalue>
          <description><![CDATA[action listener]]> </description>
        </attribute>
      </tag>
    </taglib>
    faces-config.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config>
      <managed-bean>
        <managed-bean-name>specialBtnBacking</managed-bean-name>
        <managed-bean-class>specialbtn.SpecialBtnBacking</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
      </managed-bean>
      <component>
        <component-type>SpecialBtnComponent</component-type>
        <component-class>jsfcustomcomponent.SpecialBtnComponent</component-class>
        <component-extension>
          <renderer-type>SpecialBtnRenderer</renderer-type>
        </component-extension>
      </component>
      <render-kit>
        <renderer>
          <component-family>SpecialBtnComponent</component-family>
          <renderer-type>SpecialBtnRenderer</renderer-type>
          <renderer-class>jsfcustomcomponent.SpecialBtnRenderer</renderer-class>
        </renderer>
      </render-kit>
    </faces-config>
    SpecialBtnComponent.java
    package jsfcustomcomponent;
    import javax.faces.component.*;
    import javax.faces.context.*;
    import javax.faces.el.*;
    import javax.faces.event.*;
    public class SpecialBtnComponent
        extends UIComponentBase implements ActionSource
        public static final String COMPONENT_TYPE = "SpecialBtnComponent";
        public static final String RENDERER_TYPE = "SpecialBtnRenderer";
        public String getFamily()
            return COMPONENT_TYPE;
        public SpecialBtnComponent()
            super();
            setRendererType(SpecialBtnComponent.RENDERER_TYPE);
        private String value;
        public void setValue(String value, FacesContext facesContext)
            this.value = value;
        public String getValue()
            if (null != this.value)
                return this.value;
            ValueBinding _vb = getValueBinding("value");
            if (_vb != null)
                return (String) _vb.getValue(getFacesContext());
            else
                return null;
        private MethodBinding specialBtnListener = null;
        public MethodBinding getActionListener()
            return (this.specialBtnListener);
        public void setActionListener(MethodBinding actionListener)
            this.specialBtnListener = actionListener;
        public Object saveState(FacesContext context)
            Object values[] = new Object[3];
            values[0] = super.saveState(context);
            values[1] = saveAttachedState(context, this.specialBtnListener);
            values[2] = this.value;
            return (values);
        public void restoreState(FacesContext context, Object state)
            Object values[] = (Object[]) state;
            super.restoreState(context, values[0]);
            this.specialBtnListener = (MethodBinding) restoreAttachedState(context, values[1]);
            this.value = (String) restoreAttachedState(context, values[2]);
        public void broadcast(FacesEvent event) throws AbortProcessingException
            super.broadcast(event);
            if (event instanceof ActionEvent)
                FacesContext context = getFacesContext();
                MethodBinding mb = this.getActionListener();
                if (mb != null)
                    try
                        mb.invoke(context, new Object[]
                                  {event});
                    catch (EvaluationException ex)
                        System.out.println("SpecialBtnComponent/broadcast(FacesEvent event)...EvaluationException encountered - ex.getMessage()=" + ex.getMessage());
                        ex.printStackTrace();
                ActionListener actionListener = context.getApplication().getActionListener();
                if (actionListener != null)
                    actionListener.processAction( (ActionEvent) event);
        public void queueEvent(FacesEvent e)
            if (e instanceof ActionEvent)
                e.setPhaseId(PhaseId.INVOKE_APPLICATION);
            super.queueEvent(e);
        public MethodBinding getAction()
            return null;
        public void setAction(MethodBinding methodBinding)
        public boolean isImmediate()
            return false;
        public void setImmediate(boolean _boolean)
        public void addActionListener(ActionListener actionListener)
            addFacesListener(actionListener);
        public ActionListener[] getActionListeners()
            return (ActionListener[]) getFacesListeners(ActionListener.class);
        public void removeActionListener(ActionListener actionListener)
            removeFacesListener(actionListener);
    SpecialBtnTag.java
    package jsfcustomcomponent;
    import javax.faces.component.*;
    import javax.faces.el.*;
    import javax.faces.webapp.*;
    import com.sun.faces.util.*;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
    public class SpecialBtnTag
        extends UIComponentTag
        public String value = null;
        public String specialBtnListener = null;
        private SpecialBtnComponent specialBtnComponent;
        public SpecialBtnTag()
            super();
        public String getComponentType()
            return SpecialBtnComponent.COMPONENT_TYPE;
        public String getRendererType()
            return SpecialBtnComponent.RENDERER_TYPE;
        protected void setProperties(UIComponent component)
            super.setProperties(component);
            if (! (component instanceof SpecialBtnComponent))
                throw new IllegalStateException("Component " + component.toString() +
                                                " not expected type.  Expected: jsfcustomcomponent.SpecialBtnComponent.  Perhaps you�re missing a tag?");
            specialBtnComponent = (SpecialBtnComponent) component;
            if (value != null)
                if (isValueReference(value))
                    ValueBinding vb = Util.getValueBinding(value);
                    specialBtnComponent.setValueBinding("value", vb);
                else
                    throw new IllegalStateException("The value for �value� must be a ValueBinding.");
            if (specialBtnListener != null)
                if (isValueReference(specialBtnListener))
                    MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(specialBtnListener, new Class[]{ActionEvent.class});
                    ( (SpecialBtnComponent) component).setActionListener(mb);
                else
                    MethodBinding mb = Util.createConstantMethodBinding(specialBtnListener);
                    ( (SpecialBtnComponent) component).setActionListener(mb);
        public void release()
            super.release();
            value = null;
            specialBtnListener = null;
        public void setValue(String value)
            this.value = value;
        public String getValue()
            return this.value;
        public void setSpecialBtnListener(String specialBtnListener)
            this.specialBtnListener = specialBtnListener;
        public String getSpecialBtnListener()
            return this.specialBtnListener;
    SpecialBtnRenderer
    package jsfcustomcomponent;
    import java.util.*;
    import javax.faces.component.*;
    import javax.faces.context.*;
    import javax.faces.event.*;
    import javax.faces.render.*;
    import javax.faces.el.MethodBinding;
    import javax.faces.el.*;
    public class SpecialBtnRenderer
        extends Renderer
        String value;
        public SpecialBtnRenderer()
            super();
        public void decode(FacesContext context, UIComponent component)
            try
                Map requestMap = context.getExternalContext().getRequestParameterMap();
                String clientId = component.getClientId(context);
                SpecialBtnComponent specialBtnComponent = (SpecialBtnComponent) component;
                String value = (String) requestMap.get(clientId);
                if (null != value)
                    specialBtnComponent.setValue(value, context);
                    MethodBinding mb = specialBtnComponent.getActionListener();
                    if (mb != null)
                        System.out.println("SpecialBtnRenderer/decode...mb.getExpressionString()=" + mb.getExpressionString());
                        //mb.invoke(context, new Object[0]);
                        mb.invoke(context, new Object[1]);
                    ActionEvent actionEvent = new ActionEvent(specialBtnComponent);
                    specialBtnComponent.queueEvent(actionEvent);
            catch (EvaluationException ex)
                ex.printStackTrace();
        public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException
            SpecialBtnComponent specialBtnComponent = (SpecialBtnComponent) component;
            ResponseWriter writer = context.getResponseWriter();
            String clientId = component.getClientId(context);
            value = (String) component.getAttributes().get("value");
            if (value == null)
                value = "defaultValue";
            buildSpecialBtn(writer, value, clientId, specialBtnComponent);
        private void buildSpecialBtn(ResponseWriter writer, String value, String clientId, SpecialBtnComponent component) throws java.io.IOException
            writer.startElement("table", component);
            writer.startElement("tbody", component);
            writer.startElement("tr", component);
            writer.startElement("td", component);
            value = String.valueOf(value);
            writer.startElement("input", component);
            writer.writeAttribute("type", "submit", null);
            writer.writeAttribute("name", clientId, "clientId");
            writer.writeAttribute("value", value, null);
            writer.endElement("input");
            writer.endElement("td");
            writer.endElement("tr");
            writer.endElement("tbody");
            writer.endElement("table");
    web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
      <display-name>pagerWEB</display-name>
      <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
      </servlet-mapping>
      <jsp-config>
        <taglib>
          <taglib-uri>http://jsfcustomcomponent/</taglib-uri>
          <taglib-location>/WEB-INF/jsfcustomcomponent.tld</taglib-location>
        </taglib>
      </jsp-config>
    </web-app>

Maybe you are looking for

  • Oracle EBS R12 installation problem in Windows 2003

    Hi, I am trying to install Oracle EBS R12 on Windows 2003 R2. I have installed cygwin along with required packages and also Visual studio 2005 as specified in the prerequisites of installation document. All the validations are successful before insta

  • 6230i CAR KIT PROBLEM

    Hi All, I have recently bought a car with a Nokia cak kit. Part nos; HFU-4 AX-15S MBC-15S Which, from my limited internet ability, understand amounts to a CARK-126 kit. I purchased a Nokia 6230i,which I understand works with this kit, but when I conn

  • Calling stored procedure with php

    I'm trying to call a stored procedure through php but keep getting the error message Fatal error: Call to undefined function: oci_bind_by_name() The code I have written so far is (:v_staff_id is an in parameter and the other two are outs) : $staff_id

  • XSLT Code requires for CASE

    HI, I'm very new to BI Publishere. I've to modify the oracle case stmt into XLS. CASE WHEN TRUNC (a.X_EXPIRATION_DATE) < TRUNC (SYSDATE) THEN 'Expired' ELSE 'Active' END Can any one help me out on it Edited by: user10675696 on Jan 18, 2012 3:28 AM

  • Something has gone horribly wrong...

    After a days long battle to get my cd's and audiobooks loaded on to my iPod video, all seemed well. On the four hour drive to my girlfriend's parents' house we listened to most of "The Lion, The Witch and The Wardrobe." When we got to her parents' ho