8 Replies Latest reply on Feb 11, 2008 11:47 AM by David M. Karr

    a4j:repeat creates multiple h:outputText, but not rich:tabs

    David M. Karr Newbie

      Sun JSF RI 1.2, RichFaces 3.1.4, Tomcat 6.

      I have a simple page that uses a4j:repeat in two places to iterate through a list of objects. The first one is just a "smoketest" to verify I can create multiple components iterating through the list, just creating a h:outputText. The second one is inside a rich:tabPanel, attempting to create multiple rich:tab components.

      The first loop appears to work the way I expect, but the second loop doesn't appear to do anything. None of the tabs in the repeat loop get rendered.

      The two pieces of code are this (works):

      <a4j:repeat value="#{ratingRequest.usedProperties}" var="property">
       <h:outputText value="Property ID[#{property.propertyID}] used[#{property.used}]"/>
      </a4j:repeat>

      and this (doesn't work):
      <a4j:repeat value="#{ratingRequest.usedProperties}" var="property">
       <rich:tab id="property" name="#{property.propertyID}"
       label="Property: #{property.propertyID}"
       rendered="#{property.used}">
       </rich:tab>
      </a4j:repeat>


      Is it not possible to have a4j:repeat in a a4j:tabPanel to create tabs dynamically?

        • 1. Re: a4j:repeat creates multiple h:outputText, but not rich:t
          Ilya Shaikovsky Master

          you should not use a4j:repeat or ui:repeat. It was discussed numerous times at this forum.

          In your case - you should use c:forEach.

          • 2. Re: a4j:repeat creates multiple h:outputText, but not rich:t
            David M. Karr Newbie

            c:foreach is what I tried first, before I tried a4j:repeat. That doesn't work either, but it fails in different ways.

            The following is an excerpt from my JSP:

            <c:forEach items="#{ratingRequest.usedProperties}" var="property">
             <rich:tab name="#{property.propertyID}"
             label="Property: #{property.propertyID} #{ratingRequest.loanID}"
             rendered="#{property.used}">
             </rich:tab>
            </c:forEach>


            When I run this, it gets an NPE in TabPanelRendererBase.encodeTabs() (line 327), because the "name" attribute of the resulting tab is a null pointer. In this example, the label comes out to "Property: abc", where the "loanID" attribute of the "ratingRequest" backing bean is "abc". The value of the "propertyID" attribute is actually "12345" (I watched the getter retrieve that value), but the reference in the "rich:tab" element comes out to a null pointer.

            • 3. Re: a4j:repeat creates multiple h:outputText, but not rich:t
              Ilya Shaikovsky Master

              something with your model.

              I used:

              
               <rich:tabPanel switchType="client" id="tab">
               <c:forEach items="#{capitalsBean.capitals}" var="cap">
               <rich:tab label="#{cap.name}" name="#{cap.state}">
               <h:outputText value="#{cap.timeZone}"/>
               </rich:tab>
               </c:forEach>
               </rich:tabPanel>
              
              



              Works fine. (bean code the same as used in suggestion code at demosite.)

              • 4. Re: a4j:repeat creates multiple h:outputText, but not rich:t
                Ilya Shaikovsky Master

                B.t.w. the similar code used to create dynamic toolBar in list shuttle example at demosite.

                • 5. Re: a4j:repeat creates multiple h:outputText, but not rich:t
                  David M. Karr Newbie

                  I'm very confused. My app is still not working, but now it's misbehaving differently than before. It's not getting the NPE anymore, because it's not even trying to render the tab with the null name (which shouldn't be null).

                  I've reduced the page to the minimum to demonstrate the problem. My model is very simple. I can't see how there could be anything wrong with it. I'll include my jsp, and the two bean classes. Can you see anything wrong with this?

                  <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
                  <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
                  <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
                  <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
                  <html>
                  <head>
                  <title>TabPanel</title>
                  </head>
                  <body>
                  <f:view>
                   <a4j:form>
                   <rich:messages layout="table" tooltip="true" showDetail="true" showSummary="true"/>
                   <h:outputText value="usedProperties["/>
                   <c:forEach items="#{ratingRequest.usedProperties}" var="property">
                   <h:outputText value="id[#{property.propertyID}] used[#{property.used}]"/>
                   </c:forEach>
                   <h:outputText value="]"/>
                   <h:outputText value="propertyList["/>
                   <c:forEach items="#{ratingRequest.propertyList}" var="property">
                   <h:outputText value="id[#{property.propertyID}] used[#{property.used}]"/>
                   </c:forEach>
                   <h:outputText value="]"/>
                   <rich:tabPanel id="tabPanel" switchType="client">
                   <rich:tab id="obligor" name="obligor" label="Obligor">
                   <h:panelGrid id="obligorPanelGrid" columns="3">
                   <h:outputText id="field1Out" value="Field1"/>
                   <h:inputText id="field1In" value="#{ratingRequest.field1}"/>
                   <rich:message for="field1In" showDetail="true"/>
                   </h:panelGrid>
                   </rich:tab>
                   <c:forEach items="#{ratingRequest.usedProperties}" var="property">
                   <rich:tab name="#{property.propertyID}"
                   label="Property: #{property.propertyID} #{ratingRequest.loanID}"
                   rendered="#{property.used}">
                   <h:outputText value="#{property.propertyID}"/>
                   </rich:tab>
                   </c:forEach>
                   </rich:tabPanel>
                   </a4j:form>
                  </f:view>
                  </body>
                  </html>

                  package com.wamu.ais.tabpanel;
                  
                  import java.math.BigDecimal;
                  import java.util.ArrayList;
                  import java.util.List;
                  
                  public class RatingRequestBean
                  {
                   private String loanID;
                   private Integer field1;
                   private Integer field2;
                   private Integer field3;
                   private Integer rating;
                   private List<PropertyInfo> propertyList;
                   private Integer propertyIndex;
                  
                   public String getLoanID() { return loanID; }
                   public Integer getField1() { return field1; }
                   public Integer getField2() { return field2; }
                   public Integer getField3() { return field3; }
                   public Integer getRating() { return rating; }
                   public List<PropertyInfo> getPropertyList() { return propertyList; }
                   public Integer getPropertyIndex() { return propertyIndex; }
                  
                   public List<PropertyInfo> getUsedProperties()
                   {
                   List<PropertyInfo> result = new ArrayList<PropertyInfo>();
                  
                   for (int ctr = 0; ctr < getPropertyList().size(); ++ ctr)
                   {
                   PropertyInfo property = getPropertyList().get(ctr);
                   if (property.getUsed())
                   {
                   property.setIndex(ctr);
                   result.add(property);
                   }
                   }
                  
                   return (result);
                   }
                  
                  
                   public void setLoanID(String loanID)
                   { this.loanID = loanID; }
                   public void setField1(Integer field1)
                   { this.field1 = field1; }
                   public void setField2(Integer field2)
                   { this.field2 = field2; }
                   public void setField3(Integer field3)
                   { this.field3 = field3; }
                   public void setRating(Integer rating)
                   { this.rating = rating; }
                   public void setPropertyList(List<PropertyInfo> propertyList)
                   { this.propertyList = propertyList; }
                   public void setPropertyIndex(Integer propertyIndex)
                   { this.propertyIndex = propertyIndex; }
                  
                   public RatingRequestBean()
                   {
                   setLoanID("abc");
                  
                   List<PropertyInfo> propertyList = new ArrayList<PropertyInfo>();
                  
                   for (int ctr = 0; ctr < 10; ++ ctr)
                   {
                   PropertyInfo property = new PropertyInfo();
                   property.setPropertyID("property " + (ctr + 1));
                   propertyList.add(property);
                   }
                  
                   ((PropertyInfo) propertyList.get(0)).setUsed(true);
                   ((PropertyInfo) propertyList.get(0)).setPropertyID("12345");
                   ((PropertyInfo) propertyList.get(0)).setValue(new BigDecimal(10));
                   ((PropertyInfo) propertyList.get(1)).setUsed(true);
                   ((PropertyInfo) propertyList.get(1)).setPropertyID("54321");
                   ((PropertyInfo) propertyList.get(1)).setValue(new BigDecimal(99));
                  
                   setPropertyList(propertyList);
                   }
                  }

                  package com.wamu.ais.tabpanel;
                  
                  import java.math.BigDecimal;
                  
                  public class PropertyInfo
                  {
                   private String propertyID;
                   private BigDecimal value;
                   private Integer index;
                   private boolean checked;
                   private boolean used;
                  
                   public String getPropertyID() { return propertyID; }
                   public final BigDecimal getValue() { return value; }
                   public Integer getIndex() { return index; }
                   public final boolean isChecked() { return checked; }
                  // public boolean getUsed() { return used; }
                   public boolean isUsed() { return used; }
                  
                   public void setPropertyID(String propertyID)
                   { this.propertyID = propertyID; }
                   public final void setValue(BigDecimal value)
                   { this.value = value; }
                   public void setIndex(Integer index)
                   { this.index = index; }
                   public final void setChecked(boolean checked)
                   { this.checked = checked; }
                   public void setUsed(boolean used)
                   { this.used = used; }
                  
                   public PropertyInfo()
                   {
                   setUsed(false);
                   setValue(new BigDecimal(0));
                   }
                  }


                  • 6. Re: a4j:repeat creates multiple h:outputText, but not rich:t
                    David M. Karr Newbie

                    I'm still no closer to solving this. My initial tests of this were with the Sun RI, but I've now tried it with MyFaces, and it fails in the same way, although in a different place because of the different JSF implementation. There is nothing wrong with my model that I can see. Debugging this was made a little more difficult because the HtmlTab class appears to be missing from the 3.1.4 source jar.

                    • 7. Re: a4j:repeat creates multiple h:outputText, but not rich:t
                      Ilya Shaikovsky Master

                      could you please send me sample (in war with libs and your java sources). I'll answer in this thread after investigation.

                      • 8. Re: a4j:repeat creates multiple h:outputText, but not rich:t
                        David M. Karr Newbie

                        I created a JIRA report for this, with an attached Eclipse project. It doesn't include the lib jars, but the .classpath file specifies everything that I reference, and they are all commonly available. This project used the Sun RI, but I saw similar issues using MyFaces.

                        http://jira.jboss.com/jira/browse/RF-2215?page=all

                        Is that sufficient?

                        Thanks for the help.