0 Replies Latest reply on Sep 11, 2007 9:56 AM by sansaric

    Access to value of component that triggered actionListener e

    sansaric

      What is the best way to access the value of a ajax4jsf supported component that triggered an event, in it's actionListener handler method ? When I use other jsf components that supports the valueChangeListener property, the component value can be easily accessed using a call to event.getNewValue();

      Excerpt of value change event handler code:

      public void valueChangeListenerHandler(ValueChangeEvent event) throws Exception {
      .......
      String valueOfcomponentThatTriggeredEvent =
      (String) event.getNewValue();
      }


      However, when I use an ajax4jsf component such as <a4j:support ..../>, I don't have access to event.getNewValue() since actionEvent does not support this call.

      <h:inputText value="#{bean.field1}" id="field1" required="true">
      <a4j:support event="onblur" immediate="true"
      actionListener = "#{valueChangeListenerHandler.updateDepencies}"
      reRender = "field1, field2"/>
      </h:inputText>

      I end up using code like below which gets the component value by providing the component ID to root.findComponent(ID) which is not a good practice.

      Action event handler code excerpt:
      public void updateDepencies(ActionEvent event) throws Exception {
      FacesContext context = FacesContext.getCurrentInstance();
      UIViewRoot root = context.getViewRoot();
      HtmlInputText inputComp = (HtmlInputText) root.findComponent("form:subview:field1");
      ....
      }

      I look forward to finding a better way from your responses,
      Thanks in advance for your help
      Marcel