2 Replies Latest reply on Oct 25, 2011 11:58 AM by Michael G

    Rerendering component to use updated value in bean

    Michael G Novice

      Hello,

       

      I was wondering how i can update/re-render a component to use a value from bean that was updated from a selection in a panelmenuitem.

       

      Here is a snippet of what i have.

       

       

      <h:form>
                  <h:panelGrid columns="2" columnClasses="panel,panel2" width="100%">
                      <rich:panel bodyClass="panel-custom-body">
                          <rich:panelMenu styleClass="panelMenu-custom" itemMode="ajax"
                              groupMode="ajax" groupExpandedLeftIcon="triangleUp"
                              groupCollapsedLeftIcon="triangleDown"
                              topGroupExpandedRightIcon="chevronUp"
                              topGroupCollapsedRightIcon="chevronDown" itemLeftIcon="disc">
                              <rich:panelMenuGroup label="Pojects" expanded="true">
                                  <rich:panelMenuItem label="Project 1" name="proj_1"
                                      style="background:#D80000;color:white" />
                                  <rich:panelMenuGroup label="Project 2" name="proj_2" id="p2">
                                      <rich:panelMenuItem label="Total Tasks 145"
                                          name="task1" />
                                      <rich:panelMenuItem label="Complete    125" name="task2" />
                                      <rich:panelMenuItem label="Open        15" name="task3" />
                                      <rich:panelMenuItem label="Invalid    5" name="task4" />
                                  </rich:panelMenuGroup>
                                  <rich:panelMenuItem id="p3" label="Project 3"
                                      name="proj_3" style="background:green;color:white;"
                                      actionListener="#{ProjDetailBean.handleMenuSelectionAction}">
      
                                  </rich:panelMenuItem>
                              </rich:panelMenuGroup>
                          </rich:panelMenu>
      
                      </rich:panel>
                      <rich:panel bodyClass="panel-custom-body">
                          <rich:panel id="detailsHeader"
                              header="Project Details for #{ProjDetailBean.detailsTitle}"
                              styleClass="cp-custom">
                     </rich:panel>
                </rich:panel>
           </h:panelGrid>
      </h:form>
      
      

       

       

      In the above, i want to select Project 3 and then it updates a bean with the value in ProjDetailBean.detailsTitle to be Project 3.  I then want this name to then show up on the panel's header.  Initially it is blank.  I'm able to set the detailsTitle value in the bean but how do i get the panel to rerender and pull in the value from the bean?

       

      Thanks

        • 1. Re: Rerendering component to use updated value in bean
          Michael G Novice

          I figured out how to do this using the a4j:ajax tag like so:

           

          <rich:panelMenuItem id="proj_1" label="Project 1" name="Projec1" style="background:green;color:white;" actionListener="#{ProjectSelectPanelMenuBean.handleMenuSelectionAction}">

                                  <a4j:ajax event="click" render="detailsHeader" immediate="true"></a4j:ajax>

          </rich:panelMenuItem>

           

          So this will rerender the component with the id="detailsHeader".

           

          I'm wondering now how i can convert the above into a bean that builds the menu dynamically.  I thought this would do it but it doesn't do anything that i can see, so i'm wondering if i'm using it correctly.

           

          UIPanelMenuItem item = (UIPanelMenuItem) application.createComponent(

                          fc, UIPanelMenuItem.COMPONENT_TYPE,"org.richfaces.PanelMenuItemRenderer");

           

                  AjaxBehavior ajaxBehavior = (AjaxBehavior)application.createBehavior(AjaxBehavior.BEHAVIOR_ID);

                  List<String> l = new ArrayList<String>();

                  l.add("detailsHeader");

                  ajaxBehavior.setRender(l);

                  ajaxBehavior.setImmediate(true);

                  item.addClientBehavior("click", ajaxBehavior);

           

          Thanks

          • 2. Re: Rerendering component to use updated value in bean
            Michael G Novice

            ok, i think i found my answers.  It seems that i need to set the itemMode to "server".