11 Replies Latest reply on Aug 30, 2007 9:19 AM by vjger

    Dynamic <rich:tab>

    vjger

      Hi.
      I would create a dynamic tabbed menu where the "id" e "label" parameter are "build" iterating over a collection.
      How can I obtain it?

      In fact, if I use the <c:foreach> JSTL tag, the var attribute isn't "seen".
      If I use <h:datatable> (or <rich:datatable>) I obtain a

      java.lang.IllegalStateException: No active tabs!
       org.richfaces.renderkit.TabPanelRendererBase.encodeTabs(TabPanelRendererBase.java:225)
      


      This is my example.

      
      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
       pageEncoding="ISO-8859-1"%>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich" %>
      
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      <title>Insert title here</title>
      
      <%
       java.util.List list = new java.util.ArrayList();
       list.add("foo1");
       list.add("foo2");
       request.setAttribute("list",list);
       %>
      
      </head>
      <body>
       <f:view>
       <rich:tabPanel switchType="server" >
       <rich:dataTable value="#{list}" var="obj">
       <rich:column>
       <rich:tab label="#{obj}" >
       </rich:tab>
       </rich:column>
       </rich:dataTable>
       </rich:tabPanel>
       </f:view>
      </body>
      </html>
      
      


      Thanks in advance

        • 1. Re: Dynamic <rich:tab>
          ilya_shaikovsky

          please post your example with c:forEach. I've used c:forEach for your case without a problems some time ago and it should works.

          • 2. Re: Dynamic <rich:tab>
            vjger

             

            <body>
            
             <f:view>
            
             <rich:tabPanel switchType="server" >
             <c:forEach items="${lista}" var="obj">
             <% request.setAttribute("obj",pageContext.getAttribute("obj")); %>
             <rich:tab label="#{requestScope.obj}">
            
             <h:outputText value="#{requestScope.obj}"/>
            
             </rich:tab>
             </c:forEach>
             </rich:tabPanel>
            
             </f:view>
            
            
            
            </body>
            


            It prints on ALL label tabs always the last value of the collection (foo2 in the example).

            • 3. Re: Dynamic <rich:tab>
              vjger

               

              "Vjger" wrote:
              <body>
              
               <f:view>
              
               <rich:tabPanel switchType="server" >
               <c:forEach items="${lista}" var="obj">
               <% request.setAttribute("obj",pageContext.getAttribute("obj")); %>
               <rich:tab label="#{requestScope.obj}">
              
               <h:outputText value="#{requestScope.obj}"/>
              
               </rich:tab>
               </c:forEach>
               </rich:tabPanel>
              
               </f:view>
              
              
              
              </body>
              


              It prints on ALL label tabs always the last value of the collection (foo2 in the example).


              This was in console:

              14:05:24,025 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
              org.ajax4jsf.framework.resource.ResourceNotFoundException: Resource not registered : org.richfaces.renderkit.images.TabGradientB
               at org.ajax4jsf.framework.resource.ResourceBuilderImpl.getResource(ResourceBuilderImpl.java:367)
               at org.ajax4jsf.framework.resource.ResourceBuilderImpl.getResourceForKey(ResourceBuilderImpl.java:322)
               at org.ajax4jsf.framework.resource.InternetResourceService.serviceResource(InternetResourceService.java:152)
               at org.ajax4jsf.framework.resource.InternetResourceService.serviceResource(InternetResourceService.java:141)
               at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:261)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
               at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
               at java.lang.Thread.run(Unknown Source)
              


              • 4. Re: Dynamic <rich:tab>
                ilya_shaikovsky

                the exception - just solves via CTRL+F5

                • 5. Re: Dynamic <rich:tab>
                  vjger

                   

                  "ilya_shaikovsky" wrote:
                  the exception - just solves via CTRL+F5


                  Sorry, I don't understand what you mean.

                  • 6. Re: Dynamic <rich:tab>
                    fernando_jmt

                    He meant you should press CRTL+F5 in your browser in order to clear browser cache.

                    BTW, this issue is already solved in the upcoming version.
                    http://jira.jboss.com/jira/browse/RF-401

                    • 7. Re: Dynamic <rich:tab>
                      vjger

                      Thanks to all.
                      Effectively CTRL+F5 solve the "exception problem" but it doesn't solve the "last element problem" i.e. when I use <c:foreach> the <rich:tab>'s label is always the last element of the collection as in the image

                      I repeat the code:



                      [img]http://wpop6.libero.it/ps4-2/ps/IFS/ImageFullSize?d=libero.it&u=mariner&t=d101d8937d475d112946&url=id%3A20&l=it&s=1186740287887[/img]

                       <?xml version="1.0" encoding="ISO-8859-1" ?>
                      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
                       pageEncoding="ISO-8859-1"%>
                      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
                      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
                      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
                      <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich" %>
                      
                      <html xmlns="http://www.w3.org/1999/xhtml">
                      <head>
                      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
                      <title>Insert title here</title>
                      
                      <%
                       java.util.List list = new java.util.ArrayList();
                       list.add("foo1");
                       list.add("foo2");
                       list.add("foo3");
                       request.setAttribute("list",list);
                      
                       %>
                      
                      </head>
                      <body>
                      
                       <f:view>
                      
                       <rich:tabPanel switchType="server" >
                       <c:forEach items="${list}" var="obj">
                      
                       <c:set var="obj" value="${pageScope.obj}" scope="request"/>
                       <rich:tab label="#{requestScope.obj}">
                      
                       <h:outputText value="#{requestScope.obj}"/>
                      
                       </rich:tab>
                       </c:forEach>
                       </rich:tabPanel>
                      
                       </f:view>
                      
                      
                      
                      </body>
                      </html>
                      


                      • 8. Re: Dynamic <rich:tab>

                        That works as designed. All the labels point to same #{requestScope.obj} which contains the last label from loop.

                        Your case is definitely challenging. Normally we recommends use of facelets, instead of JSP. Not so many people uses JSP now. I guess you can try to change <rich:tab label="#{requestScope.obj}"> to <rich:tab label="${requestScope.obj}">.

                        You must understand the difference between JSF and JSP - in your case forEarch will be executed first, create component tree and than tree will be rendered. Any EL expressions with # will be executed on rendering, not during the loop.

                        • 9. Re: Dynamic <rich:tab>
                          vjger

                           

                          "ishabalov" wrote:
                          I guess you can try to change <rich:tab label="#{requestScope.obj}"> to <rich:tab label="${requestScope.obj}">.



                          I receive the following Exception:


                          org.apache.jasper.JasperException: /test.jsp(33,4) According to TLD or attribute directive in tag file, attribute label does not accept any expressions
                          


                          • 10. Re: Dynamic <rich:tab>
                            yevgen_78

                            you can't use <rich:tab label="${requestScope.obj}">

                            as i see you are not using facelets.
                            so use <rich:tab label="#{requestScope.obj}">

                            • 11. Re: Dynamic <rich:tab>
                              vjger

                               

                              "yevgen_78" wrote:
                              you can't use <rich:tab label="${requestScope.obj}">

                              as i see you are not using facelets.
                              so use <rich:tab label="#{requestScope.obj}">


                              if you read my previous posts you'll see that I did it.

                              It is possible to create the tabbed menu dynamically and if yes, how?