开发者

Wicket Component hierarchy - getParent()

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>
            &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>

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 = 开发者_StackOverflownew 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜