Tapestry5 and tree selection

In the tree component, Tapestry5 allows the user to select multiple items. Each selected item appears in bold. How can I make a restriction on a tree component, so I can select one separate element?

I check the TreeSelectionModel for this purpose, but all I can do is store the TreeNode values ​​in the collection, but not limit the user selection on the client side.

Thank.

+3
source share
1 answer

This is a tricky thing. You must place the tree component in the zone and update the zone when the selection changes.

Jumpstart: http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/treefromdatabasewithzones

Psydo-:

TML:

<t:zone t:id="treeZone" id="treeZone">
  <t:tree t:id="Tree" t:model="treeModel" t:node="treeNode" t:value="categoryNode"  class="prop:leafClass">
    <p:label>
      <t:if test="treeNode.leaf">
        <a t:type="EventLink" t:event="leafSelected" t:context="categoryNode.category.id" t:zone="selectedZone" href="#">
          ${treeNode.label}
        </a>
      </t:if>
      <t:if test="!treeNode.leaf">
        ${treeNode.label}
      </t:if>
     </p:label>
  </t:tree>
</t:zone>

Java:

@InjectComponent
private Zone treeZone;

@Inject
private AjaxResponseRenderer ajaxResponseRenderer;

@Inject
private Request request;

void onLeafSelected(Integer categoryId) {
    CategoryNode categoryNode = categoryService.findCategoryInfo(categoryId);
    selectedCategory = categoryNode.getCategory();

    if (request.isXHR()) {
        ajaxResponseRenderer.addRender(treeZone).addRender(selectedZone);
    }
}

public String getLeafClass() {
    if (selectedCategory != null && categoryNode.getCategory().equals(selectedCategory)) {
        return "selected";
    }
    else {
        return "";
    }
}
+2

All Articles