Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tapestry5 and selection on tree component

Tags:

tapestry

In Tapestry5 tree component allows a user to select multiple items. Each selected item looks colored in bold. How do I make a restriction on tree component so is possible to select one single item?

I've been checking TreeSelectionModel for this purpose, but all I can do is to store TreeNode values on a collection, but not to restrict user selection on client side.

Thanks.

like image 993
dovahkiin Avatar asked Nov 22 '25 14:11

dovahkiin


1 Answers

That's a tricky one. You have to place the tree component within a zone and update the zone when the selection changes.

Geoff Callender posted an example at jumpstart: http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/treefromdatabasewithzones

Psydo-code example:

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 "";
    }
}
like image 146
Felix Scheffer Avatar answered Nov 25 '25 08:11

Felix Scheffer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!