gpt4 book ai didi

java - Wicket 组件层次结构 - getParent()

转载 作者:行者123 更新时间:2023-12-02 00:41:53 41 4
gpt4 key购买 nike

我做了一个实验。首先我想声明一下 html:

<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>
&nbsp;
</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

我的问题是:

  • “Component id = div”和“Component id = column”后面的“Component id = 0”是什么意思,这个组件是什么?
  • 倒数第二行“id = 4, version = 0”的含义是什么?

最佳答案

ID 为 0 的组件是 ListItem,它们的 ID 是它们在包含的 ListView 中的索引。

每个页面都会为每个 session 分配一个 ID(“id = 4”),请参阅 API documention of Page 中的“身份”段落。 .

每个页面都可以进行版本控制以支持后退按钮(“版本 = 0”),请参阅 API documention of Page 中的“后退按钮”段落。 。如果启用,每个页面的多个版本将存储在 session 中。新版本通常由表单提交触发。您可以尝试使用 forminput example ,使用不同的值多次提交表单,查看 URL(您可以在其中看到增加的版本)并尝试浏览器的后退按钮。

关于java - Wicket 组件层次结构 - getParent(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6137269/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com