2 Replies Latest reply on Sep 18, 2007 8:29 PM by kelvinysjboss

    h:commandButton and h:commandLink action not invoked.

    kelvinysjboss

      Hello. I'm hoping someone can help me with this issue. Here's the ordeal and i have some simple code to demonstrate. I have a series of h:commandButtons or h:commandLinks that i'm using on a rich:toolBar. These buttons are rendered based on the state of the user's action. For instance, my toolbar buttons are edit, save, and cancel, and the state the user may be in is viewing or editing. If the user is editing then the rendered attribute of the save and cancel buttons are 'true' otherwise 'false' and the if the user is just viewing the the rendered attribute of the edit button is 'true' otherwise false. So what happens is this when a user initially enters the page they are viewing the page and the appropriate button is displayed (edit). The user clicks the edit button and the action associated with that button is invoked and the state is updated to 'editing'. When the page refreshes, the appropriate buttons are displaying for the page (save, cancel). However, this time if the user clicks either of the buttons, the action associated with the button or link is not invoked and the page refreshes.

      BTW I'm using
      RichFaces 3.1.0
      JSF RI 1.2_04
      JDK 1.6
      Jetty 6.1.5 standalone
      JSP 2.1


      Here is a simple jsp document and managed bean to demonstrate this and i have the managed bean defined at request scope:

      <jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page">
      <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html" >

      <jsp:directive.page language="java"
      contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"/>

      <jsp:output doctype-root-element="html"
      doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
      doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />

      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      Test Page


      <f:view>
      <f:verbatim><h1>Test Page</h1></f:verbatim>
      <h:form>
      <rich:panel>
      <f:facet name="header">
      <rich:spacer>
      <rich:toolBar>
      <rich:toolBarGroup>
      <h1 align="center"><h:outputText value="Testing" /></h1>
      </rich:toolBarGroup>
      <rich:toolBarGroup location="right">
      <h:commandButton rendered="#{not testActions.editing}" title="Edit" alt="Edit" action="#{testActions.doEditAction}" image="/images/edit.gif" style="height:14px;width:14px;"/>
      <h:commandButton rendered="#{testActions.editing}" title="Cancel" alt="Cancel" action="#{testActions.doViewAction}" image="/images/close.png" style="height:14px;width:14px;"/>
      <h:commandLink rendered="#{testActions.editing}" action="#{testActions.doViewAction}" style="height:14px;width:14px;">
      <h:outputText value="Cancel" />
      </h:commandLink>
      </rich:toolBarGroup>
      </rich:toolBar>
      </rich:spacer>
      </f:facet>
      <h2><h:outputText value="#{testActions.state}" /></h2>
      </rich:panel>
      </h:form>
      </f:view>


      </jsp:root>


      /**
      *
      */
      package my.test.faces.controller;

      import org.apache.log4j.Logger;

      /**
      * @author Kelvin
      *
      */
      public class TestActions {
      private static final Logger logger = Logger.getLogger(TestActions.class);
      private String state;

      public TestActions() {
      state = "viewing";
      }

      public String doEditAction() {
      logger.debug(TestActions.class.getSimpleName() + "::doEditAction[]");
      state = "editing";
      return null;
      }

      public String doViewAction() {
      logger.debug(TestActions.class.getSimpleName() + "::doViewAction[]");
      state = "viewing";
      return null;
      }

      public boolean isEditing() {
      return "editing".equals(state);
      }

      public boolean isViewing() {
      return "viewing".equals(state);
      }

      public String getState() {
      if( isEditing() ) return "EDITING";
      else return "VIEWING";
      }
      }