0
我做了一個實驗。首先我想聲明的HTML:Wicket組件層次結構 - getParent()
<form wicket:id="form">
<table>
<tr>
<td>
<table style="border: 1px solid;" cellspacing="0" cellpadding="0">
<tr wicket:id="row">
<td wicket:id="column" style="border: 1px solid #3A6395">
<div wicket:id="div">
<span wicket:id="panel"></span>
<span wicket:id="tooltip"><span wicket:id="tooltipPanel"></span></span>
</div>
</td>
</tr>
</table>
</td>
<td>
</td>
</tr>
</table>
</form>
<wicket:fragment wicket:id="labelFragment">
<span wicket:id="value"></span>
</wicket:fragment>
<wicket:fragment wicket:id="linkFragment">
<a href="" wicket:id="link">
<span wicket:id="value"></span>
</a>
</wicket:fragment>
化java:
private class ReportDisplayByUserWithTaskTypeSortForm extends Form {
private static final long serialVersionUID = 10162L;
public ReportDisplayByUserWithTaskTypeSortForm(String id) {
super(id);
setOutputMarkupId(true);
addComponent();
}
private void addComponent() {
ListView row = new ListView("row", new LoadableDetachableModel() {
private static final long serialVersionUID = 10164L;
@Override
protected Object load() {
return getUserMonitorMap();
}
}) {
private static final long serialVersionUID = 10165L;
@Override
protected void populateItem(ListItem rowItem) {
@SuppressWarnings("unchecked")
List<? extends Element> columnMap = (List<Element>) rowItem.getModelObject();
ListView column = new ListView("column", columnMap) {
private static final long serialVersionUID = 10166L;
@Override
protected void populateItem(ListItem columnItem) {
Element element = (Element) columnItem.getModelObject();
WebMarkupContainer div = new WebMarkupContainer("div");
Label value = new Label("value");
Fragment fragment = null;
if (element instanceof TaskTypeLabelElement) {
fragment = new Fragment("panel", "linkFragment", this);
AjaxLink link = new AjaxLink("link") {
private static final long serialVersionUID = 10163L;
@Override
public void onClick(AjaxRequestTarget target) {
sortAsc = !sortAsc;
doSort();
target.addComponent(this.getParent().getParent().getParent().getParent().getParent().getParent().getParent());
}
};
link.add(value);
fragment.add(link);
} else {
fragment = new Fragment("panel", "labelFragment", this);
fragment.add(value);
}
// some other code goes here
columnItem.add(div);
}
};
rowItem.add(column);
}
};
add(row);
}
}
}
片段中的鏈接作爲實例:
AjaxLink link = new AjaxLink("link") {
private static final long serialVersionUID = 10163L;
@Override
public void onClick(AjaxRequestTarget target) {
System.out.println(this);
System.out.println(this.getParent());
System.out.println(this.getParent().getParent());
System.out.println(this.getParent().getParent().getParent());
System.out.println(this.getParent().getParent().getParent().getParent());
System.out.println(this.getParent().getParent().getParent().getParent().getParent());
System.out.println(this.getParent().getParent().getParent().getParent().getParent().getParent());
System.out.println(this.getParent().getParent().getParent().getParent().getParent().getParent().getParent());
System.out.println(this.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent());
System.out.println(this.getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent());
}
};
爲的System.out.println的輸出:
15:58:17,476 INFO [STDOUT] [MarkupContainer [Component id = link]]
15:58:17,477 INFO [STDOUT] [MarkupContainer [Component id = panel]]
15:58:17,477 INFO [STDOUT] [MarkupContainer [Component id = div]]
15:58:17,477 INFO [STDOUT] [MarkupContainer [Component id = 0]]
15:58:17,477 INFO [STDOUT] [MarkupContainer [Component id = column]]
15:58:17,477 INFO [STDOUT] [MarkupContainer [Component id = 0]]
15:58:17,477 INFO [STDOUT] [MarkupContainer [Component id = row]]
15:58:17,477 INFO [STDOUT] [MarkupContainer [Component id = form]]
15:58:17,477 INFO [STDOUT] [Page class = info.release.wicket.ReportDisplayByUserWithTaskTypeSort, id = 4, version = 0]
15:58:17,477 INFO [STDOUT] null
我q問題是:
- 「Component id = div」和「Component id = column」後的「Component id = 0」是什麼意思,這個組件是什麼?
- 第二行最後一行的「id = 4,version = 0」是什麼意思?