H:commandButton and actionListener

Hi all,
I'm trying to add an ActionListener to a commandButton, but there is something wrong. This is my (very simple) jsp page:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
     <title>My JSF 'index.jsp' starting page</title>
</head>
<body>
     <f:view>
          <h:form>
          hello world
          <br>
          <h:commandButton value="click me" action="none" >
               <f:actionListener type="it.hostingjava.MyListener" />
          </h:commandButton>
          </h:form>
          <br>          
     </f:view>
</body>
</html>And this is the (basic) MyListener:
package it.hostingjava;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
public class MyListener implements ActionListener {
     public void processAction(ActionEvent arg0) throws AbortProcessingException {
          System.out.println("MyListener.processAction");
}And, last but not least this is the rendered HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
     <title>My JSF 'index.jsp' starting page</title>
</head>
<body>
          <form id="_idJsp0" name="_idJsp0" method="post" action="/myjsf/index.faces" enctype="application/x-www-form-urlencoded">
          hello world
          <br>
          <input id="_idJsp0:_idJsp1" name="_idJsp0:_idJsp1" type="submit" value="click me" onclick="clear__5FidJsp0();" />
          <input type="hidden" name="_idJsp0_SUBMIT" value="1" /><input type="hidden" name="jsf_sequence" value="11" /><input type="hidden" name="_idJsp0:_link_hidden_" /><script type="text/javascript"><!--
function clear__5FidJsp0() {
  var f = document.forms['_idJsp0'];
  f.elements['_idJsp0:_link_hidden_'].value='';
  f.target='';
clear__5FidJsp0();
//--></script></form>
          <br>          
<!-- MYFACES JAVASCRIPT -->
</body>
</html>So, when i click the button in output window is printed (correctly) "MyListener.processAction" but the same behaviour is obtained when i refresh the page. Is there a way to make that the refresh doesn't fire the actionListener ?
I'm using MyFaces implementation on Tomcat 5.5.17. I'm using the latest release available. I have the same problem on Firefox and Internet Explorer.

I think the problem is that you have an action and an actionListener. Put only one of them.

Similar Messages

  • Commandbutton onclick and actionlistener happen at same time

    I started a thread previously with a similar issue, but the title of that thread really doesn't describe the current problem. Sorry for double posting, but I would delete that thread if I could.
    I have a command button as:
    <h:commandButton id="saveCloseFoil" type="submit"
    onclick="javascript:saveText();"
    action="#{Item.saveOptionAction}"
    value="#{propertiesBundle.saveCloseSubmitLabel}"
    actionListener="#{Item.setFoilTextToBean}" />
    The saveText() javascript function copies the text from a text editor to a field defined as:
    <h:inputHidden id="hiddenTextField" value="" />
    The actionlistener should take the value from the hidden field, and put it in the backing bean. The Action then saves that value in its correct place in the database.
    The problem is that the onclick and actionlistener are firing at the exact same time(i am verifying this by using the firefox javascript debugger breakpoints for the javascript and JDeveloper breakpoints for the actionlistener. Both breakpoints stop at the same time.)
    The strange thing is that in another place in our applicate we have an almost identical button:
    <h:commandButton tabindex="3" type="submit" id="submit"
    onclick="javascript:setBrowserSettings();"
    action="#{Login.loginAction}"
    actionListener="#{Login.setBrowserOSSettings}"
    value="#{propertiesBundle.loginLabel}">
    </h:commandButton>
    in which the onclick is run first, then the actionlistener, then the action. I verified this using the exact same method as with the button I am working on now.

    I use both IE6 and Firefox. I mentioned FF because I am unable to debug the problem as accurately in IE6 due to the very limited javascript debugging available for it.
    I also have tried the return true; in the onclick, and tried it again, with no change.

  • Which is executed first? af:setPropertyListener and af:commandButton's actionListener

    I have two test apps.
    First app:
    It has jsf pages. And I have a few fields and a button on the page.The backing bean for my page has a method prepareToBeUpdateOrderRelease(ActionEvent ae).
    My button looks like this:
                           <af:commandButton text="Update" id="cb3"
                                              binding="#{backingBeanScope.backing_editOrWithDetails.cb3}" action="update"
                                              actionListener="#{backingBeanScope.backing_editOrWithDetails.prepareToBeUpdateOrderRelease}">
                                <af:setPropertyListener from="#{backingBeanScope.backing_editOrWithDetails.toBeUpdateOrderRelease}"
                                                        to="#{pageFlowScope.toBeUpdatedOrderRelease}" type="action"/>
                            </af:commandButton>
    When I run the page, I can see from the printouts on the integrated weblogic console, actionListener is called first, then setPropertyListener is called.
    Second App:
    It has jspx pages. I have a few fields and a button on the page. The backing bean for my page has a method prepareToBeUpdateOrderRelease(). And this method is called in getTheUpdatedOrder().
    My button looks like this:
                                  <af:commandButton text="Submit Changes" id="cb1"
                                                      binding="#{backingBeanScope.backing_getOneOrder.cb1}"
                                                      action="callUpdate">
                                        <af:setPropertyListener from="#{backingBeanScope.backing_getOneOrder.theUpdatedOrder}"
                                                                to="#{pageFlowScope.toBeUpdatedOrder}" type="action"/>
                                    </af:commandButton>
    The page works fine as this.
    But if I want to use the same way as the first app, which is using actionListener, the page will fail, because of a NPE. From the printout, I can see setPropertyListener is executed before actionListener.
    The only difference between the two apps is jsf vs. jspx. Is this the cause of the difference of the execution sequence between setPropertyListener and actionListener? Thanks.

    User, please tell us your Jdev version!
    It's a bug and feature. Check prsync.com/oracle/setpropertylistener-and-setactionlistener-might-fire-too-late-when-using-facelets-468522/ for an explanation.
    Timo

  • Keep focus and actionlistener

    I open as a popup a custom JPanel but
    I want to keep focus and actionlistener on it
    while it is opened.
    is there a way?
    thanks for any clue

    I tried removing all the pattern validations on the field and added this below code in the validate event of the text field and it works..
    var strCode;
    var f = /^([A-Z]{2}[1-9]{5}[A-Z])$/;
    if(this.rawValue != null && String(this.rawValue) != "") {
                        strCode = String(this.rawValue);
                        if (f.test(strCode) == false) {
                                            xfa.host.messageBox("Invalid pattern!");
                                            xfa.host.resetData();
                                            xfa.host.setFocus(this);
    xfa.host.setFocus(this);

  • UICommand action and actionListener - invoke in different phases

    Hi,
    I am trying to get the action and actionListener methods of a command button invoked in different phases. When the button is pressed I would like the actionListener to be invoked immediately, but the action method only in the "invoke applications phase", unless the form validation failed.
    Setting immediate to "true" doesn't work, as I can't get the action method to be queued for later processing. I also can't make them both actionListeners as the action method controls navigation.
    Any way round this?
    Thanks!

    Action = Executed in the invoke application phase. Runs a method in a bean that returns a String object. The String is used by the navigation system to determine which page to render next. The rules for this are set up in the faces-config.xml file, in the navigation-rule sections.
    ActionListener = Executed in the invoke application phase. Is triggered when the action event occurs for the component the listener is attached too. This listener can perform miscellaneous actions required when the button is clicked, but does not return a String that affects the navigation.
    What order do they get called? Try this out!
    http://www.jsftutorials.net/faces-config/phaseTracker.html
    It'll help you understand the JSF lifecycle. Which is VERY important, especially when those weird errors start occurring (or JSF seems to be ignoring your commands).
    CowKing

  • ItemListemer and ActionListener...and others...how can they live together?

    Hi,
    I want to have a couple of DropDown Menus, some Buttons and some Checkboxes in the same class....How can I do that knowing that my class needs to implement ItemListener and ActionListener ?
    I've tried something like:
    "public class extends Applet implements ItemListener implements ActionListener"
    but not surprisingly it doesn't work....
    and what if on top of that I want a MouseListener, a WindowListener or God knows what else...?
    Thanks in advance for your help...
    Tom

    You need to read the basics about Swing events.
    For starters, you do not implement listeners in your Applet class. Instead, you add new listeners to specific components that you want to listen on. For example, if you need to perform certain actions when a JComboBox's selection changes, you would do something like:
    my_combo.addActionListener(  new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("selection changed to: " + my_combo.getSelectedItem());
    });And for buttons:
    my_button.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("You clicked " + ((JButton) e.getSource()).getText() " button);
    }MoustListener and other listeners can be similarily added. See JDK Documentation or Tutorials

  • Difference between CommandButton and CommandToolbarButton? (Loading popup )

    Hi! I created popup and CommandButton to open it. But when I try to open popup then in Server log I have error:
    <PopupRenderer><encodeAll> Loading popup: pt1:uploadWindow during a full-page request is not supported.
    But when I tried to use CommandToolbarButton, not CommandButton, then the error was gone.
    What is difference between these two buttons?
    Best regards, Debuger!

    Default value of the attribute <tt>partialSubmit</tt> is <tt>false</tt> for <af:commandButton> and <tt>true</tt> for <af:commandToolbarButton> (see tag documentation). That's why you have succeeded by using <af:commandToolbarButton>.
    <af:commandToolbarButton> is intended for use mainly inside <af:toolbar> components. When used in a toolbar the border of the button renders only when you move the mouse cursor over it.
    If you set <tt>partialSubmit="true"</tt> you will be able to open the popup using <af:commandButton> too.

  • Af:commandMenuItem action and actionListener are not executing

    Hello all!
    I use JDeveloper Studio Edition Version 11.1.1.2.0. Here's the problem. I have a popup menu like this
    <af:popup id="someMenu" animate="default">
    <af:menu id="pt_m1">
    <af:forEach var="item" items="#{ContextMenuHelperBean.availableUserRoles}">
    <af:commandMenuItem text="#{item.roleName}"
    action="#{ContextMenuHelperBean.changeUserRole_Action}"
    actionListener="#{ContextMenuHelperBean.changeUserRole_ActionListener}"
    immediate="true"
    partialSubmit="false"
    id="pt_cmi1" rendered="true">
    <f:attribute name="userRole" value="#{item}"/>
    </af:commandMenuItem>
    </af:forEach>
    </af:menu>
    </af:popup>
    The problem is that action and actionListener are not executing, when the menu item is selected (but the page is reloaded with no changes). ContextMenuHelperBean has a "session" scope set in adfc-config.xml. What can be wrong with this?

    Now I've encountered a new kind of error. I create a menu in a managed bean like this:
    In JSPX
    <f:view beforePhase="#{RolesMenuSupportBean.createMenus}">
    <af:popup id="cxtMenu" animate="default">
                            <af:menu id="pt_m1"
                                     binding="#{RolesMenuSupportBean.rolesMenu}">
                            </af:menu>
                          </af:popup>In com\cs\webb2\view\utils\menu\RolesMenuSupport.java
        public void createMenus(PhaseEvent phaseEvent) {                       
            List<IUserRole> rolesList = getAvailableUserRoles();
            for (IUserRole role: rolesList) {           
                Boolean hasItem = false;           
                for (Iterator iter = rolesMenu.getChildren().iterator(); iter.hasNext(); ) {
                    RichCommandMenuItem item = (RichCommandMenuItem) iter.next();
                    if (!hasItem)
                        hasItem = item.getText().equalsIgnoreCase(role.getRoleName());
                if (!hasItem) {
                    RichCommandMenuItem newItem = new RichCommandMenuItem();                                                       
                    newItem.getAttributes().put("userRole", role);
                    newItem.setText(role.getRoleName());
                    newItem.setId(ITEM_ID);               
                    newItem.setActionExpression(getActionExpression("#{RolesMenuSupportBean.changeUserRole_Action}"));                           
                    newItem.addActionListener(getExpressionActionListener("#{RolesMenuSupportBean.changeUserRole_ActionListener}"));                               
                    rolesMenu.getChildren().add(newItem);  
        } The menu is created successfully, but when I click on any item, I get an exception
    <b>javax.servlet.ServletException: Method not found: com.cs.webb2.view.utils.menu.RolesMenuSupport@d4702.changeUserRole_Action(void)</b>
    But of course I have such a method in my com.cs.webb2.view.utils.menu.RolesMenuSupport:
    In com\cs\webb2\view\utils\menu\RolesMenuSupport.java
        public String changeUserRole_Action()
            System.out.println("Action!");
            // no code yet
            return "adfMenu_Main";
        }And there <b>is</b> a managed bean named RolesMenuSupportBean, which is associated with class com.cs.webb2.view.utils.menu.RolesMenuSupport.
    Can anyone tell me, what can be wrong?

  • CommandButton and commandLink behaving differently for file download

    Hello there,
    Hopefully someone can help - I have looked through the existing queries and can't just find what I'm after.
    I have a main record with asociated files - the files are uploaded through my web app and are downloaded from the same page that lists the files in a dataTable. I have a series of commandLinks that display the file names - a user selects the file and it downloads.
    The problem I have is that when a user downloads a file then immediately trys to upload another, they are prompted to download the file that they have already previously downloaded. If however I replace the commandLinks for commandButtons the application behaves correctly.
    I have seen an associated link that mentions similar behaviour (http://blogs.sun.com/tor/entry/creating_downloadable_files), however I do not want to use the command buttons in this manner, and I use an actionListener rather than an action so I may retrieve information from the list of dynamically created files. I am not receiving any errors, just the strange behaviour with commandLinks.
    My code is as follows:
    public void downloadFile(ActionEvent ev) {
    UIData fileList = findParentHtmlDataTable(ev.getComponent());
    AssociatedFile associatedFile = (AssociatedFile) fileList.getRowData();
    String downloadPath = "download path retrieved here...";
    try {
    byte[] fileData = InternalUtil.readFile(downloadPath);
    HttpServletResponse response =
    (HttpServletResponse) getFacesContext().getExternalContext().getResponse();
    response.setHeader("Content-disposition", "attachment; filename=\"" +
    associatedFile.getName() +
    response.setContentLength(fileData.length);
    response.setContentType(associatedFile.getContentType());
    ServletOutputStream out = response.getOutputStream();
    out.write(fileData);
    getFacesContext().getApplication().getStateManager().saveSerializedView(getFacesContext());
    getFacesContext().responseComplete();
    } catch (FileSystemException e) {
    getFacesContext().addMessage("null", new FacesMessage("Error downloading file: " +
    e.getMessage()));
    } catch (IOException e) {
    getFacesContext().addMessage("null", new FacesMessage("Error downloading file: " +
    e.getMessage()));
    Any help would be greatly appreciated!
    Thanks in anticipation, Carl

    Which JSF version are you using? Try upgrading to newer version if needed. http://javaserverfaces.dev.java.net

  • Difference between action and actionListener

    I would like to tell me which is the difference between an action and an actionListener in the following example:
    <h:form style="text-align:center">
    <h:commandButton image="mountrushmore.jpg"
    actionListener="#{rushmore.listen}"
    action="#{rushmore.act}"/>     
    </h:form>Which method of the rushmore bean is invoked first the listen() or the act()? Based on the JSF lifecycle the action events are invoked in the Invoke Application Phase correct?So first we have the process of validation and then the action is invoked right?And then the listener?
    Thanks in advance.

    Action = Executed in the invoke application phase. Runs a method in a bean that returns a String object. The String is used by the navigation system to determine which page to render next. The rules for this are set up in the faces-config.xml file, in the navigation-rule sections.
    ActionListener = Executed in the invoke application phase. Is triggered when the action event occurs for the component the listener is attached too. This listener can perform miscellaneous actions required when the button is clicked, but does not return a String that affects the navigation.
    What order do they get called? Try this out!
    http://www.jsftutorials.net/faces-config/phaseTracker.html
    It'll help you understand the JSF lifecycle. Which is VERY important, especially when those weird errors start occurring (or JSF seems to be ignoring your commands).
    CowKing

  • CommandButton and commandLink strange behaving

    I use <h:commandButton value="ok" action="{#bean.method}"/>
    bean.method returns null to stay on same page. when I run it on localhost everything is OK. when I deploy application on server, then action method is never called and nothing is happend (neither exception)
    it same is happend with commandLink

    I use <h:commandButton value="ok"
    action="{#bean.method}"/> you misplaced '#'.. Try this..
    action="#{bean.method}"Message was edited by:
    w4c

  • Observable and ActionListener.. help

    Is there anyway to pause update method and continue after I click the �Add Student� button?
    The update method is called automatically when my observable object is changed, so I can�t display previous observable information via the button�s ActionListener.
    Anyway to do that?
    Thanks
    import java.util.Observable;
    import java.util.Observer;
    import java.awt.event.*; //package for event handeler
    import java.awt.*;
    import javax.swing.*;
    public class Lab5Frame extends JFrame implements Observer {     
         private JLabel label;
         private String name;     
         public TestFrame(Observable observable) {
              System.out.println("Windows created.");
              observable.addObserver(this);
         public Lab5Frame(String title) throws HeadlessException {
              super(title);          
              Container c = getContentPane();
              JPanel panel = new JPanel();
              label = new JLabel(name);
              panel.add(this.label);
              JButton button = new JButton("Add Studnet");
              button.addActionListener(new ListName());           
              c.add(button, BorderLayout.NORTH);
              c.add(panel, BorderLayout.CENTER);
              //*** window adapter
              addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent we){
                        System.exit(0);
         private class ListName implements ActionListener{
              public void actionPerformed(ActionEvent event){                    
                   //what should I write here to performe the updated information
    vai the update method?
         //oberver update     
         public void update(Observable arg0, Object arg1) {     
              System.out.println("LogConsole: " + arg1);
         }

    Is there anyway to pause update method and continue after I click the �Add Student� button?
    The update method is called automatically when my observable object is changed, so I can�t display previous observable information via the button�s ActionListener.
    Anyway to do that?
    Thanks
    import java.util.Observable;
    import java.util.Observer;
    import java.awt.event.*; //package for event handeler
    import java.awt.*;
    import javax.swing.*;
    public class Lab5Frame extends JFrame implements Observer {     
         private JLabel label;
         private String name;     
         public TestFrame(Observable observable) {
              System.out.println("Windows created.");
              observable.addObserver(this);
         public Lab5Frame(String title) throws HeadlessException {
              super(title);          
              Container c = getContentPane();
              JPanel panel = new JPanel();
              label = new JLabel(name);
              panel.add(this.label);
              JButton button = new JButton("Add Studnet");
              button.addActionListener(new ListName());           
              c.add(button, BorderLayout.NORTH);
              c.add(panel, BorderLayout.CENTER);
              //*** window adapter
              addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent we){
                        System.exit(0);
         private class ListName implements ActionListener{
              public void actionPerformed(ActionEvent event){                    
                   //what should I write here to performe the updated information
    vai the update method?
         //oberver update     
         public void update(Observable arg0, Object arg1) {     
              System.out.println("LogConsole: " + arg1);
         }

  • H:commandButton and attribute image

    I cannot make work a h:commandButton that contains an image.When
    the browser opens a see "a not found image" icon.
    The code is
    <h:commandButton image="/images/englishFlag.jpg"
                        actionListener="#{rushmore.listen}"
                        action="#{rushmore.act}"/>     However I don't thing there is any problem with the image Url since the following component displays the image with no problem
    <h:graphicImage value="/images/englishFlag.jpg" style="border:0px"/>Any suggestion?

    try taking out the leading slash.. ? Sorry not very useful but you never know. If you could give a mapping of your directories

  • Buttons and actionlistener help.

    the following code has 2 buttons, how would i use a button to get me differnt graphics but inside the same window,
    say i clicked next the graphics would be slightly altered which I will do but it wont open a new window it will be in the same window, but different shapes.
    I am having trouble with action listeners and really need help in how they work iv read up but dont understand, and how this would be implemented for this.
    much help would be appreciated.
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.RenderingHints;
    import java.awt.Stroke;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Rectangle2D;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class square extends JPanel
        public square()
            setPreferredSize(new Dimension(800, 700));
            int eb = 80;
            setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
            setLayout(new BorderLayout(5, 10));
           JPanel buttonPanel = createButtonPanel();
             add(buttonPanel, BorderLayout.SOUTH);
        private JPanel createButtonPanel()
            JPanel bp = new JPanel();
            bp.setOpaque(false);
                   JButton btn2 = new JButton("<-  Back Step ");
                    JButton btn = new JButton("Next Step   ->");
                    bp.add(btn2);
                    bp.add(btn);
            return bp;
        @Override
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            Rectangle2D rect = new Rectangle2D.Double(250, 150, 100, 100);
            Rectangle2D     rect2 = new Rectangle2D.Double(400, 150, 100, 100);
             Rectangle2D     rect3 = new Rectangle2D.Double(550, 150, 100, 100);
             Rectangle2D     rect4 = new Rectangle2D.Double(250, 300, 100, 100);
             Rectangle2D     rect5 = new Rectangle2D.Double(400, 300, 100, 100);
             Rectangle2D     rect6 = new Rectangle2D.Double(550, 300, 100, 100);
             Rectangle2D     rect7 = new Rectangle2D.Double(250, 450, 100, 100);
             Rectangle2D     rect8 = new Rectangle2D.Double(400, 450, 100, 100);
             Rectangle2D     rect9 = new Rectangle2D.Double(550, 450, 100, 100);
             g.drawString("b0,0", 300, 130);
            g.drawString("b1,0", 300, 110);
             g.drawString("b2,0", 300, 90);
                 g.drawString("b0,1", 450, 110);
            g.drawString("b1,1", 450, 90);
            g.drawString("b2,1", 450, 70);
                 g.drawString("b0,2", 600, 90);
            g.drawString("b1,2", 600, 70);
            g.drawString("b2,2", 600, 50);
             g.drawString("a0,0", 200, 200);
            g.drawString("a1,0", 150, 200);
             g.drawString("a2,0", 100, 200);
                 g.drawString("a0,1", 150, 350);
            g.drawString("a1,1", 100, 350);
            g.drawString("a2,1", 50, 350);
                   g.drawString("a0,2", 100, 500);
            g.drawString("a1,2", 50, 500);
            g.drawString("a2,2", 15, 500);
            g2.setPaint(Color.black);
            g2.draw(rect);
            g2.draw(rect);
              g2.draw(rect2);
             g2.draw(rect3);
              g2.draw(rect4);
             g2.draw(rect5);
              g2.draw(rect6);
             g2.draw(rect7);
              g2.draw(rect8);
              g2.draw(rect9);
            Stroke oldStroke = g2.getStroke();
            g2.setStroke(new BasicStroke(5));
            g2.setStroke(oldStroke);
        private static void createAndShowUI()
            JFrame frame = new JFrame("Matrix Multiplication - Step by Step ");
            frame.getContentPane().add(new square());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }

    ok I had a look over it, I got this
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.RenderingHints;
    import java.awt.Stroke;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Rectangle2D;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class square extends JPanel implements ActionListener
        public square()
            setPreferredSize(new Dimension(800, 700));
            int eb = 80;
            setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
            setLayout(new BorderLayout(5, 10));
           JPanel buttonPanel = createButtonPanel();
             add(buttonPanel, BorderLayout.SOUTH);
      public void actionPerformed(ActionEvent e) {
            System.out.println("hello");
        private JPanel createButtonPanel()
            JPanel bp = new JPanel();
            bp.setOpaque(false);
                   JButton btn2 = new JButton("<-  Back Step ");
                    JButton btn = new JButton("Next Step   ->");
                    bp.add(btn2);
                    bp.add(btn);
             btn.addActionListener(this);
            return bp;
        @Override
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            Rectangle2D rect = new Rectangle2D.Double(250, 150, 100, 100);
            Rectangle2D     rect2 = new Rectangle2D.Double(400, 150, 100, 100);
             Rectangle2D     rect3 = new Rectangle2D.Double(550, 150, 100, 100);
             Rectangle2D     rect4 = new Rectangle2D.Double(250, 300, 100, 100);
             Rectangle2D     rect5 = new Rectangle2D.Double(400, 300, 100, 100);
             Rectangle2D     rect6 = new Rectangle2D.Double(550, 300, 100, 100);
             Rectangle2D     rect7 = new Rectangle2D.Double(250, 450, 100, 100);
             Rectangle2D     rect8 = new Rectangle2D.Double(400, 450, 100, 100);
             Rectangle2D     rect9 = new Rectangle2D.Double(550, 450, 100, 100);
             g.drawString("b0,0", 300, 130);
            g.drawString("b1,0", 300, 110);
             g.drawString("b2,0", 300, 90);
                 g.drawString("b0,1", 450, 110);
            g.drawString("b1,1", 450, 90);
            g.drawString("b2,1", 450, 70);
                 g.drawString("b0,2", 600, 90);
            g.drawString("b1,2", 600, 70);
            g.drawString("b2,2", 600, 50);
             g.drawString("a0,0", 200, 200);
            g.drawString("a1,0", 150, 200);
             g.drawString("a2,0", 100, 200);
                 g.drawString("a0,1", 150, 350);
            g.drawString("a1,1", 100, 350);
            g.drawString("a2,1", 50, 350);
                   g.drawString("a0,2", 100, 500);
            g.drawString("a1,2", 50, 500);
            g.drawString("a2,2", 15, 500);
            g2.setPaint(Color.black);
            g2.draw(rect);
            g2.draw(rect);
              g2.draw(rect2);
             g2.draw(rect3);
              g2.draw(rect4);
             g2.draw(rect5);
              g2.draw(rect6);
             g2.draw(rect7);
              g2.draw(rect8);
              g2.draw(rect9);
            Stroke oldStroke = g2.getStroke();
            g2.setStroke(new BasicStroke(5));
            g2.setStroke(oldStroke);
        private static void createAndShowUI()
            JFrame frame = new JFrame("Matrix Multiplication - Step by Step ");
            frame.getContentPane().add(new square());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }it produces hello once I click the button, but how would I produce the same frame once the button is clicked, not a new frame, the same one iv got with slight adjustments inside it..which i will do.

  • Differences between h:commandButton and h:commandLink

    I have a problem with h:commandButton. I want to send parameters when I execute a h:commandButton, but I don't receive anything. With h:commandLink I don't have any problems for receive parameters in the next page. I don't understand why?!?!? any ideas??

    I guess you want to pass some parameter
    which is a constant value defined by the page author,
    is not input by the end user.
    CommandButton can receive information only by the properties of the managed bean.
    Usually the properties are bound to the end user's input.
    But using faces-config.xml, the page author can specify some value
    as the property of a managed bean as follows:
    <faces-config>
        <managed-bean>
            <managed-bean-name>bean</managed-bean-name>
            <managed-bean-class>MyActionBean</managed-bean-class>
            <managed-bean-scope>request</managed-bean-scope>
            <managed-property>
                <property-name>param</property-name>
                <value>Any constant value for the parameter</value>
            </managed-property>
        </managed-bean>
    </faces-config>
    <h:commandButton value="go" action="bean.action"/>In the MyActionBean.action method,
    you can use getParam() to access the value specified in faces-config.xml.
    Otherwise, if you want to place several buttons which call a same action with
    different parameters, you should combine h:dataTable and h:commandButton.

Maybe you are looking for

  • How to go from AppleScript 1.0 to 1.9 or higher?

    Maybe this is a stupid question, but I wonder how I could move from AppleScript 1.0 to 1.9 or higher. I recently downloaded a programme that requires at least 1.9. I then checked my AppleScript version that was installed as part of the Tiger installa

  • How to Disable Automatic Java Update

    HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy  EnableJavaUpdate            Type=REG_DWORD               Data=0x000000000 (1)     Replace 1 with 0 and you are good.

  • Error in extraction via FTP using mdmgx trx in R3

    Hi, I am using SAP MDM 5.5 and use mdmgx trx for extraction in R3. When i try to start extraction via ftp (i.e Upload via FTP) in mdmgx trx, it shows me error: "<i>User <username> has no access authorization for computer <IP address></i>" I can local

  • Central Person ID issue

    Hi, We are running Payroll and it dumped. On further investigation we came to know that it's dumping for a particular employee. On checking the master data, it was found Central Person ID is missing for that employee. What is the best way to create C

  • R40 dual boot options

    I have an R40 2897-54U. It has been a multiboot machine with WinXP, Knoppix and Debian Sarge installed. I decided to load Debian Lenny and have wiped the contents of the hard drive to start fresh. (I didn't delete the hidden partition however, since