2011-05-26 57 views
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> 
      &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 

我q問題是:

  • 「Component id = div」和「Component id = column」後的「Component id = 0」是什麼意思,這個組件是什麼?
  • 第二行最後一行的「id = 4,version = 0」是什麼意思?

回答

3

ID爲0的組件是ListItem s,它們的ID是它們在包含ListView中的索引。

爲每個會話分配一個ID(「id = 4」),請參閱API documention of Page中的「身份」段落。

每個頁面都可以針對後退按鈕支持進行版本控制(「版本= 0」),請參閱API documention of Page中的「後退按鈕」段落。如果啓用,會話中會存儲每個頁面的多個版本。新版本通常由表單提交觸發。您可以使用forminput example進行試用,使用不同的值多次提交表單,查看URL(您可以在其中查看增加的版本)並嘗試瀏覽器的後退按鈕。