In case I wasn't clear enough about the problem, here is an example...

I have a tree root. It is not expanded. It has a checkbox, which is not checked.
[+][ ] root

Then I expand the root, which reveals 2 children. The children too have checkboxes that are not checked.
[-][ ] root
   |
   - [ ] child1
   |
   - [ ] child2

I now check the root and the 2 children. If I were to submit now, everything would work as expected. Values from all 3 checkboxes would submit. But I won't...
[-][x] root
   |
   - [x] child1
   |
   - [x] child2

... Instead I will hide the children again, leaving only the root visible.
[+][x] root

Finally, I submit the tree. In my backing bean I will then only receive the checkbox value of the root. The checkbox value of child1 and child2 is not submitted.

Has anyone else, who have used tree2 and selectManyCheckbox / treeCheckbox / selectBooleanCheckbox, managed to get around this limitation somehow?


- Bjørn Stenfeldt


----- Original Message ----- From: "Bjørn Stenfeldt" <[EMAIL PROTECTED]>
To: <users@myfaces.apache.org>
Sent: Wednesday, July 05, 2006 9:00 AM
Subject: Values from tree checkboxes not submitted, when checkboxes are hidden.


Hello

Im am trying to use tree2 with checkboxes, and have made everything work, except for one tiny detail. Each node in the tree has a selectManyCheckbox. My problem is that if I expand a node, check some of the checkboxes in the children, and hide the children again, the values from the checkboxes for those children are not submitted. Only values from checkboxes that are visible in my browser, when I click my submit button, are submitted. This is a huge problem, since many users without doubt will hide some of the nodes before they finally submit a tree.

Anyone know how I can change this behaviour?

Here is my code:



JSF:
<html:form id="createHost">
<tomahawk:tree2 id="clientTree" value="#{ModuleBean.moduleHierarchy}"
               var="node" showRootNode="false" clientSideToggle="true">
   <core:facet name="root">
       <html:panelGroup>
           <tomahawk:htmlTag value="div">
               <html:outputText value="#{node.description}"/>
               <html:outputText value=" (#{node.childCount})"
                                styleClass="childCount"
                                rendered="#{!empty node.children}"/>
           </tomahawk:htmlTag>
       </html:panelGroup>
   </core:facet>
   <core:facet name="module">
       <html:panelGroup>
           <tomahawk:htmlTag value="div">
               <tomahawk:selectManyCheckbox id="moduleId" layout="spread"

converter="#{HostBean.moduleIdTreeConverter}"
                                            value="#{HostBean.moduleId}">
                   <tomahawk:treeCheckbox for="moduleId"
                                          itemValue="#{node.identifier}"

itemLabel="#{node.description}"/>
               </tomahawk:selectManyCheckbox>
               <html:outputText value=" (#{node.childCount})"
                                styleClass="childCount"
                                rendered="#{!empty node.children}"/>
           </tomahawk:htmlTag>
       </html:panelGroup>
   </core:facet>
</tomahawk:tree2>
<html:commandButton value="OK" action="#{HostBean.updateHostAction}" style="width: 25%;" styleClass="button"/>
</html:form>



HostBean:
private void addModuleId(String moduleId) {
   if (moduleId != null && !moduleId.equals(""))
       if (!this.moduleId.contains(moduleId))
           this.moduleId.add(moduleId);
}
public List getModuleId() {
   return moduleId;
}
public void setModuleId(List moduleId) {
   for (int i = 0; i < moduleId.size(); i++) {
       String value = (String)moduleId.get(i);
       addModuleId(value);
   }
}
public Converter getModuleIdTreeConverter() {
   return new Converter() {
       public Object getAsObject(FacesContext context,
               UIComponent component, String newValue)
               throws ConverterException {
           addModuleId(newValue);
           return newValue;
       }
       public String getAsString(FacesContext context,
               UIComponent component, Object value)
               throws ConverterException {
           return (String)value;
       }
   };
}
public void loadHost(ActionEvent event) {
/* Initializes data, when the user first clicks the edit button on a host.
    Loads both host data and modules. Modules are added using
    the addModuleId(String) method. */
}
public String updateHostAction() {
   CachingServiceLocator csl = CachingServiceLocator.getInstance();
   HostLocal hostLocal = csl.lookupHostBean();
   Integer[] moduleId = new Integer[this.moduleId.size()];
   for (int i = 0; i < moduleId.length; i++) {
       moduleId[i] = Integer.valueOf((String)this.moduleId.get(i));
   }
   try {
       hostLocal.updateHost(id, languageId, currencyId,
               moduleId, name, mail, address);
   }
   catch (UpdateException ue) {}
   return "success";
}


ModuleBean:
private void addChildModules(TreeNode node, TOList modules) {
   for (int i = 0; i < modules.getLimitedSize(); i++) {
       ModuleTO module = (ModuleTO)modules.get(i);
       TreeNode child = new TreeNodeBase("module",
               module.getName(), String.valueOf(module.getId()), false);
       node.getChildren().add(child);
       addChildModules(child, module.getChildModules());
   }
}
public TreeNode getModuleHierarchy() {
   CachingServiceLocator csl = CachingServiceLocator.getInstance();
   ModuleLocal ml = csl.lookupModuleBean();
   TreeNode base = new TreeNodeBase("root", "ROOT", false);
   addChildModules(base, ml.loadModuleHierarchy());
   return base;
}



I am using Tomahawk 1.1.3 with the JSF 1.1 that comes with Netbean IDE 5.0. Guess maybe that makes it Sun's RI of JSF.

Yours sincerely,

Bjørn Stenfeldt

Reply via email to