Wicket 组件层次结构 - getParent()

发布于 2024-11-09 23:58:35 字数 6210 浏览 1 评论 0原文

我做了一个实验。首先我想说明 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 = 0”的含义是什么”和“组件id=列”,这个组件是什么?
  • 倒数第二行的“id = 4,version = 0”是什么意思?

I did an experiment. First I want to state the 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>
             
        </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>

The 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);
        }
    }
}

The link within the fragment is instantiating as:

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());
        }
    };

The output for 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

My questions are:

  • What is the meaning of "Component id = 0" after "Component id = div" and "Component id = column", what is this component?
  • What is the meaning of "id = 4, version = 0" of the second last line?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪梦之恋 2024-11-16 23:58:35

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

每个页面的每个会话都会分配一个 ID(“id = 4”),请参阅 Page 的 API 文档

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

The components with ID 0 are the ListItems, their ID is their index in the containing ListView.

Each page is assigned an ID per session ("id = 4"), see the "Identity" paragraph in the API documention of Page.

Each page may be versioned for back button support ("version = 0"), see the "Back Button" paragraph in the API documention of Page. If enabled, multiple versions per page are stored in the session. New versions are usually triggered by form submits. You may try it with the forminput example, submit the form multiple times with different values, take a look at the URL (where you can see the increasing version) and try the back button of your browser.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文