1 Reply Latest reply on Sep 28, 2011 5:27 AM by djnose

    rich:tabPanel and switchType

    djnose

      Hi, i just have a question to clarify my understanding of switchType with a <rich:tabPanel>

      I do have the following simple page: (it is imported and wrapped into a form)

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html
         
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:ui="http://java.sun.com/jsf/facelets">
      <rich:tabPanel switchType="ajax">
      <rich:tab header="Active Stuff">
      <ui:include src="/Stuff/operator/activeStuff .xhtml"/>
      </rich:tab>
      <rich:tab header="Stuff">
      <ui:include src="/Stuff/operator/Stuff .xhtml"/>
      </rich:tab>
      <rich:tab header="Feature">
      <p>Here you would see all features</p>
      </rich:tab>
      </rich:tabPanel>
      </html>

       

      in /Stuff/operator/Stuff .xhtml i do have simple list which executes a SQL and so on. My Question is:

      Why are the getter called from the bean where the tab is not active?

      What does switchType="ajax" mean? Does that not mean "Load and render only the active tab"?

      Why are all tabs rendered even if they are not active?

       

      Thank you!

        • 1. Re: rich:tabPanel and switchType
          djnose

          is this such a dump question? Or is it just not possible to render parts of the tab?

          I want my getter only be called if i click on the second tab.

          How can i manage that easy?

           

          currently i did it like that:

          - created a binding variable

          - wrote a function which checks the active tab and then gets the list

           

          that looks quite "dirty" and feels like a hack... any better way to do that? What are tabs good for, if they load all data directly without being active?

           

          Some code:

          /**
               * thats kind of weird, we try to figure out if this tab is really active before we get any Objects from the database.
               * We do not want the SQL be executed twice!
               *
          @param tabId
               *
          @return
               */

             
          private boolean checkIfTabIsActive(String tabId) {
                  List<UIComponent> tabs =
          routingTabPanel.getChildren();
          for (UIComponent component : tabs) {
                     
          if (component instanceof UITab) {
                          UITab tab = (UITab) component;
          if (tab.getId().equals(tabId) && tab.isActive()) {
          return true;
          }
                      }
                  }
                 
          return false;
          }

           

              /**
          * that part has always been executed before. Even if the page / tab was not active

              */

             public List<ChimeraRoute> getAllRoutes() {
                 
          if (checkIfTabIsActive("route")) {
                     
          if (allRoutes == null || allRoutes.isEmpty()) {
                         
          allRoutes = getRoutesById(getOperatorId(), false);
          }
                  }
                 
          return allRoutes;
          }

           

           

          and the JSF PAGE
             
          <rich:tabPanel switchType="ajax" id="routingTabPanel" binding="#{routeOperatorBean.routingTabPanel}">
          <rich:tab header="Active Routing" id="activeRoute" >
          <ui:include src="/Route/operator/operatorActiveRoute.xhtml"/>
          </rich:tab>
          <rich:tab header="Routing" id="route">
          <ui:include src="/Route/operator/operatorRoutes.xhtml"/>
          </rich:tab>
          <rich:tab header="Feature" id="feature">
          <p>Here you would see all features per route</p>
          </rich:tab>
          </rich:tabPanel>

           

          Is there anything "nice" i could do?

          Thx