Thanks for the response. Attached is the markup and the java classes for the
panel. It's slightly modified since normally a DataView is used, but the
behaviour is the same with the ListView. This is only the panel class and not
a complete quickstart.

Here is the markup

<html xmlns:wicket>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>TreeDataViewPanel</title>
  </head>
  <body>
    <wicket:panel>
      <table>
        <thead>
          <tr>
            <th></th>
            <th>Name</th>
            <th>Vorname</th>
          </tr>
        </thead>
        <tbody>
          <div wicket:id="overview">
            <div wicket:id="extendingRow">USer Data here</div>
          </div>
        </tbody>
      </table>
    </wicket:panel>
  </body>
</html>

<wicket:fragment wicket:id="rowView">
  <tr>
    <td>
      <a wicket:id="extendLink">
        <span wicket:id="extendSymbol">Arrow</span>
      </a>
    </td>
    <td>
      <div wicket:id="name">Name</div>
      <div wicket:id ="details">
        <ul>
          <li><b>Again</b><span wicket:id="strasse">Strasse</span></li>
        </ul>
      </div>
    </td>
    <td><span wicket:id="vorname">Vorname</span></td>
  </tr>
</wicket:fragment>

and the corresponding Java

public class TreeDataViewPanel extends Panel {

  private List<String> userList = Arrays.asList("User 1","User 2","User 3");

  public TreeDataViewPanel(String id) {
    super (id);
    ListView<String> userTable = new ListView<String>("overview", userList) {
      @Override
      protected void populateItem(ListItem<String> item) {
        String user = item.getModelObject();

        DetailFragment dataView =
          new DetailFragment("extendingRow","rowView",user);
        dataView.setOutputMarkupId(true);
        item.add(dataView);
      }
    };
    add(userTable);
  }
}

class DetailFragment extends Fragment {

 private boolean compressed = true;

  public boolean isCompressed() {
    return compressed;
  }

  public void setCompressed(boolean compressed) {
    this.compressed = compressed;
  }

  public DetailFragment(String id, String markupId, String user) {
    super(id, markupId);

    WebMarkupContainer detailContainer = new WebMarkupContainer("details") {
      @Override
      public boolean isVisible() {
        return !isCompressed();
      }
    };

    add(new DropDownLink("extendLink", this));
    add(new Label("name", user));
    add(new Label("vorname", user));

    detailContainer.add(new Label("strasse", user));
    add(detailContainer);
  }
}


class DropDownLink extends AjaxLink {

  DetailFragment parent;
  Label compressedSymbol = new Label("extendSymbol","\u25B6"); // 9654
  Label expandSymbol = new Label("extendSymbol","\u25BC");     // 9660
  Label linkSymbol;

  @Override
  public void onClick(AjaxRequestTarget target) {
    if (parent.isCompressed()) {
      linkSymbol.replaceWith(expandSymbol);
      linkSymbol = expandSymbol;
      parent.setCompressed(false);
    } else {
      linkSymbol.replaceWith(compressedSymbol);
      linkSymbol = compressedSymbol;
      parent.setCompressed(true);
    }
    target.addComponent(linkSymbol);
    target.addComponent(parent);
  }

  public DropDownLink(String id, DetailFragment parent) {
    super(id);
    linkSymbol = compressedSymbol;
    linkSymbol.setOutputMarkupId(true);
    expandSymbol.setOutputMarkupId(true);
    compressedSymbol.setOutputMarkupId(true);
    this.parent = parent;
    add(linkSymbol);
  }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to