2 Replies Latest reply on Jan 27, 2008 4:25 AM by liat

    rich tree with check boxes - problem with specific check box

    liat

      Hi,

      I created a rich tree with check boxes.
      each root node is a category and under each category there are 2 lists of items: items from type A and items from type B.
      (each category can have either A items or B items but not both).

      My problem is that the check box of the last B item is not working.
      All the other check boxes are working fine.

      In the example below the category "Fruit" has 2 B items and the second is not working (I click the check box and it turns to false immediately).

      When there is only one B item - it's not working
      When there are more than 2 items - the last item is not working

      I want to emphasis that my problem is different from problems that were posted in the forum so far. the problems that were posted said that expanding the nodes makes the check box work and it is not the case here. also the problem occurred for most users when there was single leaf under the category and my problem occurs even when there are more.

      Here are the code samples: (I work with rich faces 3.2.1)

      <div>
       <h:panelGroup>
       <table cellpadding="0" cellspacing="0" class="size100">
       <tr>
       <td>
       <rich:tree id="categoryTree" switchType="ajax">
       <!-- ******** Category Nodes ******** -->
       <rich:treeNodesAdaptor nodes="#{categoryTreeBean.categoryItems}" var="ci">
       <rich:treeNode>
       <h:outputText value="#{ci.category}" />
       </rich:treeNode>
       <!-- ******** Type B Nodes ******** -->
       <rich:treeNodesAdaptor nodes="#{ci.typeBItems}" var="b_item">
       <rich:treeNode>
       <h:selectBooleanCheckbox value="#{b_item.selected}">
       <a4j:support event="onclick" ajaxSingle="true" reRender="typeBPanel"/>
       </h:selectBooleanCheckbox>
       <h:panelGroup id="typeBPanel">
       <h:outputText
       rendered="#{b_item.selected}"
       style="color: blue; cursor: pointer;font-weight: bold;font-style: italic; text-decoration:underline"
       value="#{b_item.description}"/>
       <h:outputText
       rendered="#{!b_item.selected}"
       style="font-weight: bold" value="#{b_item.description}" />
       </h:panelGroup>
       </rich:treeNode>
       </rich:treeNodesAdaptor>
       <!-- ******** Type A Nodes ******** -->
       <rich:treeNodesAdaptor nodes="#{ci.typeAItems}" var="a_item">
       <rich:treeNode>
       <h:selectBooleanCheckbox value="#{a_item.selected}">
       <a4j:support event="onclick" ajaxSingle="true" reRender="typeAPanel"/>
       </h:selectBooleanCheckbox>
       <h:panelGroup id="typeAPanel">
       <h:outputText
       rendered="#{a_item.selected}"
       style="color: blue; cursor: pointer;font-weight: bold;font-style: italic; text-decoration:underline"
       value="#{a_item.description}"/>
       <h:outputText
       rendered="#{!a_item.selected}"
       style="font-weight: bold" value="#{a_item.description}" />
       </h:panelGroup>
       </rich:treeNode>
       </rich:treeNodesAdaptor>
       </rich:treeNodesAdaptor>
       </rich:tree>
       </td>
       </tr>
       </table>
       </h:panelGroup>
       </div>


      here are the classes for type A item and type B item:

      public class TypeAItem {
      
       private String description;
      
       private boolean selected;
      
       private BigDecimal price;
      
       public String getDescription() {
       return description;
       }
      
       public void setDescription(String description) {
       this.description = description;
       }
      
       public boolean isSelected() {
       return selected;
       }
      
       public void setSelected(boolean selected) {
       this.selected = selected;
       }
      
       public BigDecimal getPrice() {
       return price;
       }
      
       public void setPrice(BigDecimal price) {
       this.price = price;
       }
      
      }
      
      public class TypeBItem {
      
       private String description;
      
       private boolean selected;
      
       private Map<String,BigDecimal> pricePerCustomer;
      
       public String getDescription() {
       return description;
       }
      
       public void setDescription(String description) {
       this.description = description;
       }
      
       public boolean isSelected() {
       return selected;
       }
      
       public void setSelected(boolean selected) {
       this.selected = selected;
       }
      
       public Map<String, BigDecimal> getPricePerCustomer() {
       return pricePerCustomer;
       }
      
       public void setPricePerCustomer(Map<String, BigDecimal> pricePerCustomer) {
       this.pricePerCustomer = pricePerCustomer;
       }
      
      }


      here is the code of the backing bean:

      public class CategoryTreeBean {
      
       private Map<String,ItemsPerCategory> categoryItems = new HashMap<String, ItemsPerCategory>(3);
      
       public void setInit(@SuppressWarnings("unused") boolean dummy) {
      
       List <TypeAItem> a_items = new ArrayList<TypeAItem> (3);
       TypeAItem a_item = new TypeAItem();
       a_item.setDescription("Cake");
       a_item.setPrice(new BigDecimal ("12.00"));
       a_items.add(a_item);
      
       a_item = new TypeAItem();
       a_item.setDescription("Chocolate");
       a_item.setPrice(new BigDecimal ("4.00"));
       a_items.add(a_item);
      
       a_item = new TypeAItem();
       a_item.setDescription("Waffles");
       a_item.setPrice(new BigDecimal ("13.75"));
       a_items.add(a_item);
      
       ItemsPerCategory ipc = new ItemsPerCategory();
       ipc.setCategory("Sweet");
       ipc.setTypeAItems(a_items);
       categoryItems.put("Sweet", ipc);
      
       a_items = new ArrayList<TypeAItem> (3);
       a_item = new TypeAItem();
       a_item.setDescription("Milk");
       a_item.setPrice(new BigDecimal ("5.20"));
       a_items.add(a_item);
      
       a_item = new TypeAItem();
       a_item.setDescription("Cheese");
       a_item.setPrice(new BigDecimal (" 8.00"));
       a_items.add(a_item);
      
       ipc = new ItemsPerCategory();
       ipc.setCategory("Dairy");
       ipc.setTypeAItems(a_items);
       categoryItems.put("Dairy", ipc);
      
       List <TypeBItem> b_items = new ArrayList<TypeBItem> (1);
       TypeBItem b_item = new TypeBItem();
       b_item.setDescription("Apple");
       b_items.add(b_item);
      
       b_item = new TypeBItem();
       b_item.setDescription("Bannana");
       b_items.add(b_item);
      
       ipc = new ItemsPerCategory();
       ipc.setCategory ("Fruit");
       ipc.setTypeBItems(b_items);
       categoryItems.put("Fruit", ipc);
      
       }
      
      public List<ItemsPerCategory> getCategoryItems () {
      
       Comparator<ItemsPerCategory> categoryComparator = new Comparator<ItemsPerCategory>(){
      
       public int compare(ItemsPerCategory c1, ItemsPerCategory c2) {
      
       return c1.getCategory().compareTo(c2.getCategory());
       }
       };
      
       List<ItemsPerCategory> data = new ArrayList<ItemsPerCategory> ();
       data.addAll(categoryItems.values());
       Collections.sort(data,categoryComparator);
       return data;
       }
      }


      Do you have any idea what is the problem ?

      Thanks,

      Liat.

        • 1. Re: rich tree with check boxes - problem with specific check
          viggo.navarsete

          Hi,

          after reading your problem, but before looking at the code, my first assumption was that it had to be something about indexes, that you weren't traversing or looking up the correct item from some list. But, after reading the code as well, I'm really not sure what you're doing :) Is there some code that you haven't posted yet?
          What happens if you have a category with A items, does it work as expected? If the category contains either one or two A items, does it work as expected?

          • 2. Re: rich tree with check boxes - problem with specific check
            liat

            Hi,

            Thanks for your reply.
            Category with A items works perfect, exactly as expected, in both cases (single item / many items)

            This is why it is so strange.
            The problem is only in the last B item.