3 Replies Latest reply on Jun 27, 2007 7:43 AM by Martin Suter

    Rerender component with backing bean (binding attribute)

    Martin Suter Newbie


      i want to rerender a backing bean, if i click on a link with an action listener.
      Is that possible?

      I've made the following sample.
      The outputText with id="rep" will be updated successfully (i use a value binding).
      The outputText with the backing bind (binding) doesn't update.

      Java 1.5.0_11
      Tomahawk 5.5
      MyFaces 1.1.5
      Ajax4JSF 1.1.1


      <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
      <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
      <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
      <%@ taglib prefix="a4j" uri="https://ajax4jsf.dev.java.net/ajax" %>
      <%@ include file="pages/noCache.jsp" %>
      <a4j:page format="html-transitional">
       <a4j:log hotkey="M" />
       <a4j:commandLink actionListener="#{bean.perform}" reRender="rep,aaa">
       <h:outputText value="testlink"/>
       <h:inputText size="50" value="#{bean.text}" >
       <a4j:support event="onkeyup" reRender="rep"/>
       <h:outputText value="#{bean.text}" id="rep"/>
       <h:outputText binding="#{bean.output}" id="aaa"/>

      Simple Java bean:
      package com.assentis.docwrite.htmlclient.beans;
      import javax.faces.component.html.HtmlOutputText;
      import javax.faces.event.ActionEvent;
      public class Bean
       private String text;
       private String aaa = "Nothing";
       public String getText() {
       return text;
       public void setText(String text) {
       this.text = text;
       public void perform(ActionEvent event)
       this.text = "link performed";
       this.aaa = "output element changed";
       public HtmlOutputText getOutput()
       HtmlOutputText text = new HtmlOutputText();
       return text;

      in faces-config.xml:

       <value />

        • 1. Re: Rerender component with backing bean (binding attribute)
          Martin Suter Newbie

          I've found a (very ugly) solution, but it works:

          1. added action="update" to the ajax command link

          2. added this navigation rule to faces-config.xml:


          But now, the whole page will be refreshed!
          What I want is, that only the outputtext with id="aaa" and id="rep" will be updated on the view side...

          • 2. Re: Rerender component with backing bean (binding attribute)
            Sergey Smirnov Master

            yes, it will be non-ajax response. Moreover, the component tree will be re-built.

            For the testing purpose, replace

            <a4j:commandLink actionListener="#{bean.perform}" reRender="rep,aaa">
             <h:outputText value="testlink"/>

            <h:commandLink actionListener="#{bean.perform}">
             <h:outputText value="testlink"/>

            Does the values are updated as you expect?

            • 3. Re: Rerender component with backing bean (binding attribute)
              Martin Suter Newbie

              Hi Sergey,
              thanks for your response!

              yes, the values are updated too...

              But my goal is to use the ajax functionality and not to refresh the whole
              page... I have to find a solution to rerender a backing bean... is that possible?

              Maybe there's a chance to rebuild some parts of the jsf view in the bean.perform method, like this way:

              1. Click on the ajax command link
              2. JSF calls action listener on bean.perform
              3. Refreshing only the view from the output element with id = "aaa"
              4. on the view side: rerendering of "rep" and "aaa"