title: JSF Ajax Update not updating the component
body: <p>Following is the scenario. I have left panel which contains all the menu items. When I click on the menu item the corresponding pages should be loaded in the center / main panel with out page refresh. So I use ajax (setupdate method) to load the page when the menu item is clicked. </p>
  
  <p>My requirement is I have the same page loaded for some set of menu items. But based on the menu item selection I need to retrieve the records from the database hence the page layout remains the same. But I get the same page served for all the menu items. Only for the first time, the call is sent to the backing bean and for subsequent clicks, no call is made to the backing bean and the same page is getting served.</p>
  
  <p>I am using PrimeFaces 3.4.1 and JSF 2.0</p>
  
  <p>Note: I am dynamically loading the screen. In Client page, I use #{menuMB.screenName} to load the screen dynamically. </p>
  
  <p>Following is the code snippet.</p>
  
  <h2>Template page</h2>
  
  <pre><code>&lt;f:view contentType="text/html; charset=UTF-8" encoding="UTF-8" &gt;
  
          &lt;div id="outerWrapper"&gt;
  
              &lt;div id="contentWrapper"&gt;
                  &lt;div id="leftPanel"&gt;
                      &lt;div class="companylogo"&gt;
  
                      &lt;/div&gt;
                      &lt;div class="jsmenu"&gt;
                          &lt;ui:insert name="leftPanel"&gt;
                          &lt;/ui:insert&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div id="mainContentWrapper"&gt;
                      &lt;div id="pageHeader"&gt;
                          &lt;ui:insert name="pageHeader"&gt;
                          &lt;/ui:insert&gt;
                      &lt;/div&gt;
                      &lt;div id="mainContent"&gt;
                          &lt;div id="mainStyle"&gt;
                              &lt;ui:insert name="mainContent"&gt;
                              &lt;/ui:insert&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="clearFloat"&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="clearFloat"&gt;&lt;/div&gt;
              &lt;div id="footer"&gt;
                  &lt;ui:insert name="footer"&gt;
                  &lt;/ui:insert&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/f:view&gt;
  </code></pre>
  
  <h2>Client XHTML</h2>
  
  <p>All the pages are loaded inside the mainOutputPanel which is inside the mainContentForm. I am getting the screen name that needs to be loaded from the backing bean menuMB.</p>
  
  <pre><code>&lt;h:body&gt;
      &lt;ui:composition template="/pages/protected/templates/layoutTemplate.xhtml"&gt;
  
  
          &lt;ui:define name="pageHeader"&gt;
              &lt;ui:include src="/pages/protected/templates/loginHeader.xhtml"&gt;
              &lt;/ui:include&gt;
          &lt;/ui:define&gt;
          &lt;ui:define name="leftPanel"&gt;
              &lt;h:form id="leftMainForm"&gt;
                  &lt;ui:include src="/pages/protected/templates/requestfactoryleft.xhtml"&gt;
                  &lt;/ui:include&gt;
              &lt;/h:form&gt;
          &lt;/ui:define&gt;
          &lt;ui:define name="mainContent" &gt;
              &lt;h:form id="mainContentForm" enctype="multipart/formdata" prependId="true"&gt;
                  &lt;h:panelGroup id="mainOutputPanel" layout="block" &gt;
                      &lt;ui:include src="#{menuMB.screenName}"&gt;
                      &lt;/ui:include&gt;
                  &lt;/h:panelGroup&gt;
  
              &lt;/h:form&gt;
  
          &lt;/ui:define&gt;
          &lt;ui:define name="footer"&gt;
              &lt;ui:include src="/pages/protected/templates/footer.xhtml"&gt;
              &lt;/ui:include&gt;
          &lt;/ui:define&gt;
      &lt;/ui:composition&gt;
  
  &lt;/h:body&gt;
  </code></pre>
  
  <h2>Left XHTML (Contains the menu which is loaded dynamically from the database)</h2>
  
  <pre><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:p="http://primefaces.org/ui"
              xmlns:f="http://java.sun.com/jsf/core" 
              xmlns:c="http://java.sun.com  /jsp/jstl/core"&gt;
  
       &lt;div class="testmenu" style="padding:7px; 
               border-radius: 10px 10px 10px 10px; margin-top: 7px; 
               background: darkgray;  width: 187px;"&gt;
          &lt;div id="rfMainMenu"&gt;
              &lt;p:panelMenu id="rfleftMainMenu" model="#{menuMB.mnuModel}" &gt;
              &lt;/p:panelMenu&gt;
          &lt;/div&gt;
  
       &lt;/div&gt;
  
  
  &lt;/ui:composition&gt;
  </code></pre>
  
  <h2>Backing bean (to load the pages dynamically when menu item is selected)</h2>
  
  <pre><code>@SessionScoped
  @ManagedBean(name = "menuMB")
  public class MenuMB implements Serializable {
  
  
      @PostConstruct
      public void loadMenu() {
  
        if (getLoggedUser() != null) {
            fmList = loginService.getMenuForUser(getLoggedUser());
        }
  
      //Call createMenu method to populate the sub menu and menu items
  
       createMenu(fmList);
    }
  
      public void loadScreensForUser(ActionEvent event) {
          MenuItem menuItem = (MenuItem) event.getComponent();
          String attrName;
  
      try {
          if (menuItem != null) {
              selectedMenuItem = menuItem.getId();
  
              //Get the screen name from the properties file
              menuUrl = RequestFactoryContextUtil.getResourceBundleString(menuItem.getId());
  
              //Set the screen name to be displayed
              setScreenName(menuUrl);
  
              //Call update to update the form  
            RequestContext.getCurrentInstance().update("mainContentForm:mainOutputPanel");
  
          }
  
  
      } 
  
      catch (Exception exc) {
  
      }
  
    }
  
  
    private void createMenu(List&lt;FunctionMaster&gt; fmList) {
      //Submenu rfSubMenu = new Submenu();
  
      try {
          if (fmList != null) {
              for (FunctionMaster sub : fmList) {
                  if (sub.getParentFunctionID() == 0) {
                      Submenu rfSubMenu = new Submenu();
                      rfSubMenu.setLabel(sub.getScreenDisplayName());
                      getMnuModel().addSubmenu(rfSubMenu);
  
                      for (FunctionMaster item : fmList) {
                          if (item.getParentFunctionID() != 0) {
                              if (item.getParentFunctionID() == sub.getFunctionID()) {
  
                                  MenuItem rfSubItem = new MenuItem();
  
                                  rfSubItem.setId(item.getFunctionName() + item.getFunctionID().toString());
                                  rfSubItem.setValue(item.getScreenDisplayName());
  
                                  rfSubItem.setImmediate(true);
  
                                  rfSubItem.setUpdate(":mainContentForm:mainOutputPanel");
                                  rfSubItem.setAjax(true);
                                  rfSubItem.setRendered(true);
                                  rfSubItem.setIcon("search");
                                  //rfSubItem.setIcon("ui-icon-search");
  
                                   ExpressionFactory factory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
                                   //rfSubItem.setActionExpression(factory.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), #{menuMB.loadScreenFromMenu}", Void.class, new Class[]{ActionEvent.class}));
                                   MethodExpression methodExpr = factory.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{menuMB.loadScreensForUser}", Void.class, new Class[]{ActionEvent.class});
                                   MethodExpressionActionListener actionListener = new MethodExpressionActionListener(methodExpr);
                                   rfSubItem.addActionListener(actionListener);
  
                                   rfSubMenu.getChildren().add(rfSubItem);
                                  //addMenuItem(rfSubItem);
                              }
                          }
                      }
                      //mnuModel.addSeparator(new Separator());
  
                  }
  
              }
          }
        } catch (Exception ex) {
          String excep = ex.getMessage();
      }
  
    }
  
  }
  </code></pre>