Can the wicket: child tag be inserted under another component on the page?

In Wicket 1.4, I am trying to allow child pages to change the CSS class on a tag on the parent page, which I do all the time. What is strange in this case is that the tag I want to target is wrapping the layout of the child page . Here was a simplified snapshot of what I tried:

ParentPage.html

<div id="main" wicket:id="main"> <wicket:child /> </div> 

ParentPage.java

 public abstract class ParentPage { private WebMarkupContainer main; protected ParentPage() { main = new WebMarkupContainer("main"); add(main); } public void setClassAttr(String cssClass){ main.add(SimpleAttributeModifier("class", cssClass); } } 

ChildPage.html

 <wicket:extend> ... </wicket:extend> 

ChildPage.java

 public class ChildPage extends Page { ... public ChildPage() { super(); ... setClassAttr("specific-class-for-this-page"); } } 

... Which explodes because it displays HTML from child downloads, but not java. (If I remove the gate: id and java code on div#main , everything will be fine.)

Note that the parent tag I want to manipulate with the child actually wraps the wicket:child tag. In other cases, I did something similar, tags that I want monkeys, which are usually siblings or otherwise removed from the wicket:child tag.

All I really want to do is let the child change the class attribute for the parent - is there any other way to do this? Why can't a child page be inserted into another component of a Wicket page?

+4
source share
6 answers

First of all, this has nothing to do with the actual setting of the attribute, but with the placement of <wicket:child> inside the container.

Now imagine if ChildPage was Panel , what would your ParentPage code look like? It will contain a string somewhere, saying main.add( new ChildPanel() ) . The way the main component knows that when rendering it, it must also call the rendering method of your child panel.

But with inheritance, it is different. Your main component cannot figure out what <wicket:child> should call. Labeling the transparent container main tells Wicket to request the parent component (that is, the component of your page) for its resolution and rendering.

+3
source

I would like to note that this was filmed with Wicket 1.5. So, if you use Wicket 1.5 or higher, you should use TransparentWebMarkupContainer instead of WebMarkupContainer.isTansparentResolver() . I also had the same problem as the poster. I have an external containing div that wraps the wicket: child tag, and I adjust its width (Twitter bootstrap grid) based on the content it should display. My mainContentContainer is 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 completely hidden, and the mainContentContainer changes to class="span9" to use an unused viewport.

See here .

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

+7
source

It works great. on the component where the gate is located: id = "main" do what is higher.

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

and an exception does not occur.

+1
source

I believe your child page extends the parent page. Why not pass the class name to the parent constructor, for example

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

The employee found a fix - make a component about the gate: child tag - "transparentResolver". +1 to anyone who can clearly articulate how it works for sure?

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

I think your use of the gate (or at least the code you sent) is strange (I tried with 1.4.22) ...

 public abstract class ParentPage { 

You may have forgotten extends WebPage .

 public class ChildPage extends Page { 

here you want to expand ParentPage I think.

Everything works as expected, and the final HTML is generated

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

My recommendation: "Do not use the HTML identifier for wicket elements when you do not need it."

0
source

Source: https://habr.com/ru/post/1340644/


All Articles