1 Reply Latest reply on Dec 29, 2011 2:08 PM by shayan

    Unbable to isolate Ajax rendered area for ui:include loaded view in richfaces 4.x

    shayan

      Hi All,


       

      I want to develop a web app that contains an "Menu Area" and "Active Area". That "Active Area" points to a page in the "Controller" managed bean and loads it by ajax request. The page to be loaded is set by ajax request through "A4j:Commandlink" and renders the "Active Area'. Here is the code

       

      1. Index.xhtml

      <ui:composition template="template.xhtml">
            <ui:define name="menu">
                 <ui:include src="menu.xhtml" />
            </ui:define>
       
            <ui:define name="body">
                 <h:panel width="100%" id="mainPanel">
                           <ui:include id="MainIncludeArea" src="#{controller.currentView}"/>
                 </h:panel>
            </ui:define>
       </ui:composition>
      

      ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      2. Menu.xhtml

      <ui:composition>
            <h:form id="menuForm">
                 <ul>
                      <li><a4j:commandLink value="Include 1" render="mainPanel" actionListener="#{controller.setInclude1}" /> </li>
                 </ul>
            </h:form>
       </ui:composition>
      

      ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      3. Include1.xhtml

       

      <ui:composition>
            Included Page 1
            <h:form id="f1">
                 <a4j:commandButton id="cb1" actionListener="#{controller.action}" value="click"/>
            </h:form>
       </ui:composition>
      


      ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      4. Controller.java

       

      @ManagedBean
      @ApplicationScoped
      public class Controller {
          String currentView;
         public Controller() {
            this.currentView = "include.xhtml";
          }
       
         public void action() {
            System.out.println("### Button Clicked ###");
          }
       
      
           public void setInclude1() {
            currentView = "include_1.xhtml";
          }
       
          public String getCurrentView() {
            System.out.println(" ### returning view ###" + currentView);
            return currentView;
          }
      }
      

       

       

      Now, when a page is loaded to active area that as you see contains a "a4j:commandButton" with an actionListener, if the button is clicked, instead of calling the listener method, the page is loaded again, and the when the second time the button is clicked,  the page is loaded as well as the listener method is called. Which means that whole page is refreshed again and view is then set and method is called. In richfaces 3.3.x, I used to use "a4j:include"  for the active area. Everything worked fine. Now in richfaces 4.x, I have to use ui:include component.  3.3.x had “a4j:region” component to isolate a region. But in 4.x its bahavious has been changed.


       

      Now I dont know how to isolate this region to be re-rendered and the Ajax request. I want only the active are to be changed instead of the whole page to be refreshed.

       

       

      Thanks