3 Replies Latest reply on Mar 3, 2009 4:40 AM by Moshe Elisha

    Add a4j:include dynamically from java

    Yaniv David Newbie

      Hello,

      I'm trying to add a4j:include inside a rich tab component dynamically from Java .
      But the include tag isn't being processed. I'm also trying to use UIinclude.
      Note adding an inputText Component does work.
      here is my code:


      public void addTab(ActionEvent event)
       {
       try {
       HtmlTabPanel tabPanel;
      
       FacesContext context = FacesContext.getCurrentInstance();
       Application application = context.getApplication();
      
       tabPanel = (HtmlTabPanel)context.getViewRoot().findComponent("form1:tabs");
       HtmlTab tab = (HtmlTab)application.createComponent(HtmlTab.COMPONENT_TYPE);
       HtmlInputText inputText = new HtmlInputText();
      
       UIInclude includeTag = (UIInclude)application.createComponent(UIInclude.COMPONENT_TYPE);
       Include A4Jinclude = new Include();
      
       A4Jinclude.setId("inc" + this.count++);
       A4Jinclude.setViewId("snippet.xhtml");
      
       includeTag.setId("inc" + this.count++);
       includeTag.setViewId("snippet.xhtml");
      
       tab.setLabel("YANIV TEST");
       tab.setId("newtab" + this.count);
      
       tab.getChildren().add(A4Jinclude);
       tab.getChildren().add(includeTag);
      
       tab.getChildren().add(inputText);
      
       tabPanel.getChildren().add(tab);
       tabPanel.setSelectedTab("newtab" + this.count);
      
       this.count++;
      
       context.renderResponse();
       } catch (FacesException ex) {
       Audit.error("", ex);
       }
       }
      


      How can I make this work?

      Thank you very much in advance,
      Yaniv.

        • 1. Re: Add a4j:include dynamically from java
          Moshe Elisha Newbie

          Hey,

          I am having the same problem. Did you find a solution?

          • 2. Re: Add a4j:include dynamically from java
            Yaniv David Newbie

            No sorry mate.
            I got no more hair on my head from this.

            I tried to do something else using YUI tabs
            adding a tab from javascript and setting it's data src to a url
            but there is a different problem with doing that; The viewstate id is causing problems since it's generating another view id and reseting it for all others. :(

            If you have something please let me know.
            Thanks.

            • 3. Re: Add a4j:include dynamically from java
              Moshe Elisha Newbie

              In my case I needed dynamic tabs but all the tabs had the same content so I did it using c:forEach tag:

              r="http://richfaces.org/rich"
              c="http://java.sun.com/jstl/core"
              


              <r:tabPanel id="systemHealthTabPanel" switchType="ajax" selectedTab="#{healthMonitor.selectedSubSystemID}" >
               <c:forEach items="#{healthMonitor.subSystemTabs}" var="subSystemTab">
               <r:tab name="#{subSystemTab.id}" label="#{subSystemTab.label}" action="#{healthMonitor.buildHealthData}">
               <f:subview id="subSystemSubview#{subSystemTab.id}" rendered="#{healthMonitor.selectedSubSystemID == subSystemTab.id}">
               <a4j:include id="subSystemTabInclude" viewId="/pages/systemHealth/systemHealthPerSubSystem.xhtml"/>
               </f:subview>
               </r:tab>
               </c:forEach>
               </r:tabPanel>
              


              The subSystemTabs return an array of SubSystemTab which has two fields id and label.