Can a wicket:child tag be nested under another Component on the Page?

孤人 提交于 2019-12-05 15:02:20

First of all, it has nothing to do with actually setting the attribute, but with putting <wicket:child> inside a container.

Now imagine if ChildPage was a Panel, what would the code of your ParentPage look like? It would contain a line somewhere saying main.add( new ChildPanel() ). That's how the main component knows that when it renders, it should call the rendering method of your child panel too.

But with inheritance it's different. Your main component has no way of knowing what <wicket:child> should resolve to. Marking your main container transparent tells Wicket to ask the parent component (that is, your page component) to resolve and render it.

Chad Smith

I would just like to point out that this has been removed as of Wicket 1.5. So, if you are using Wicket 1.5 or higher, you would use a TransparentWebMarkupContainer component instead of WebMarkupContainer.isTansparentResolver(). I also had the same problem as the poster. I have an outer, containing div which wraps a wicket:child tag, and I adjust its width (Twitter Bootstrap fluid grid) based on the content that it needs to display. My mainContentContainer is a TransparentWebMarkupContainer:

<div class="row-fluid">
    <div class="span3" wicket:id="sidebarPanel"></div>
    <div class="span6" wicket:id="mainContentContainer">
        <wicket:child/>
    </div>
    <div class="span3" wicket:id="rightPanel"></div>
</div>

Sometimes the rightPanel is completely hidden, and the mainContentContainer changes to class="span9" to take up the unused viewport.

See here.

Thanks for posting. I had the exact same problem until I read this post.

primosz67

it's working great. on the component where is wicket:id="main" do what is above.

ain = new WebMarkupContainer("main") {
    private static final long serialVersionUID = 1L;

    @Override
    public boolean isTransparentResolver() {
        return true;
    }
};

and exception do not occur.

I suppose your childpage extends the parentpage. Why not pass the class name into the parent's constructor like

public class ChildPage extends ParentPage {    
   public ChildPage() {
     super("my-class");
   }
}

A co-worker found the fix - make the component about the wicket:child tag a "transparentResolver". +1 to anyone who can clearly articulate how this works precisely?

    main = new WebMarkupContainer("main") {
        private static final long serialVersionUID = 1L;
        @Override
        public boolean isTransparentResolver() {
            return true;
        }
    };
    add(main);

I think, that your wicket usage (or at least code you posted) is strange (I tried with 1.4.22)...

public abstract class ParentPage {

Probably you forgot extends WebPage.

public class ChildPage extends Page { 

here you want to extends ParentPage I guess.

Everything works as expected and final HTML generated is

<div id="main" wicket:id="main" class="specific-class-for-this-page">
    <wicket:child>
        <wicket:extend>
            text
        </wicket:extend>
    </wicket:child>
</div>

My recommendation is "do not use HTML id for wicket elements when you do not need to".

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!