1 Reply Latest reply on Jul 16, 2008 12:01 PM by Tsikhon Kuprevich

    Dynamically generated rich:TabPanel

    Peter Wendland Newbie

      Hello together!

      first for your information: I'm using RichFaces 3.2.0 with tomcat 5.5.26 (since I'm in the middle of my project right now I can't change the RF version).

      I have a question: I want to dynamically create a rich:tabPanel element and as many rich:tabs inside as needed (according to my data retrieved from the DB). I also want the tabPanels have ajax-behavior (switchType).

      I got the dynamic creation working, but when clicking on a different tab I get following error:


      14.07.2008 15:56:16 com.sun.faces.lifecycle.LifecycleImpl phase
      WARNUNG: executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@1259ee0) threw exception
      java.lang.NullPointerException
       at org.ajax4jsf.context.AjaxContextImpl.convertId(AjaxContextImpl.java:592)
       at org.ajax4jsf.context.AjaxContextImpl.addComponentToAjaxRender(AjaxContextImpl.java:579)
       at org.ajax4jsf.renderkit.AjaxRendererUtils.addRegionByName(AjaxRendererUtils.java:911)
       at org.richfaces.component.UITab.setupReRender(UITab.java:93)
       at org.ajax4jsf.component.AjaxActionComponent.setupReRender(AjaxActionComponent.java:98)
       at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:60)
       at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:316)
       at org.ajax4jsf.component.AjaxViewRoot.broadcastAjaxEvents(AjaxViewRoot.java:335)
       at org.ajax4jsf.application.AjaxViewHandler.processAjaxEvents(AjaxViewHandler.java:206)
       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:182)
       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:256)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:362)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
       at com.as.seak.utils.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:50)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
       at java.lang.Thread.run(Thread.java:619)
      javax.servlet.ServletException
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:256)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:362)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
       at com.as.seak.utils.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:50)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
       at java.lang.Thread.run(Thread.java:619)
      

      My Java-Code:
      
       private HtmlTabPanel tabPanel;
      
       tabPanel = new HtmlTabPanel();
      
       Application application = FacesContext.getCurrentInstance().getApplication();
       List<UIComponent> childTabs = tabPanel.getChildren();
      
       HtmlTab tab2 = (HtmlTab) application.createComponent(HtmlTab.COMPONENT_TYPE);
       childTabs.add(tab2);
       tID = "0812345A-02";
       tab2.setLabel(tID);
       tab2.setName(tID);
       tab2.setValue("this is the value object");
       tab2.setActive(true);
       tabPanel.setSwitchType("ajax");
      

      And the static code:
      <h:form id="transactionOverview">
       <rich:tabPanel switchType="ajax" binding="#{transactionBean.tabPanel}"/>
       <rich:tabPanel switchType="ajax">
       <rich:tab label="First">Here is tab #1</rich:tab>
       <rich:tab label="Second" disabled="true">Here is tab #2</rich:tab>
       <rich:tab label="Third">Here is tab #3</rich:tab>
       </rich:tabPanel>
      </h:form>
      


      The upper tabPanel is being created, that's ok so far. But when clicking into a panel I get the error.
      Clicking into a panel of the lower tabPanel it works fine.

      What must I specify and which attributes have to be set that I can get it working without any errors?
      Who can help me getting this solved?

      Another question: does anywhere a manual / developer guide exist for generating GUI elements dynamically?

      Thank You in advance!
      Peter

        • 1. Re: Dynamically generated rich:TabPanel
          Tsikhon Kuprevich Newbie

          Hi, it looks fine for me.

          I tried the following method:

           public void actionListener(ActionEvent actionEvent) {
           Application application = FacesContext.getCurrentInstance().getApplication();
          
           List<UIComponent> childTabs = tabPanel.getChildren();
          
           HtmlTab tab2 = (HtmlTab) application.createComponent(HtmlTab.COMPONENT_TYPE);
          
           String tID = "a0812345A-022";//error on digits in the beginning
           tab2.setId(tID);
           tab2.setLabel(tID);
           tab2.setName(tID);
           tab2.setValue("this is the value object");
           tab2.setActive(true);
          
           UIOutput output = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
           output.setValue("content");
          
           tab2.getChildren().add(output);
          
           tabPanel.setSwitchType("ajax");
          
           childTabs.add(tab2);
           }


          And how my page looks like:
           <h:form id="transactionOverview">
          
           <rich:tabPanel switchType="ajax" binding="#{custom.tabPanel}">
           <rich:tab label="First">Here is tab #1</rich:tab>
           <rich:tab label="Second" disabled="true">Here is tab #2</rich:tab>
           <rich:tab label="Third">Here is tab #3</rich:tab>
           </rich:tabPanel>
          
           <a4j:commandButton value="Add Tab" id="button"
           actionListener="#{custom.actionListener}"
           reRender="transactionOverview"/>
          
           </h:form>