问题描述
在Wicket 1.4中,我试图允许子页面在父页面的标签上改变一个CSS类,而这一点我一直都在做。这种情况有些奇怪,我想要定位的标签包装子页面标记。以下是我尝试过的一个简化剪辑:ParentPage.html
< div id =mainwicket: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);
}
}
...因为它出现了来自小孩的HTML 加载,但不是java。(如果我在 div#main
中删除了wicket:id和java代码,一切正常。)
请注意,我想从操作的父上的标签实际上是将 wicket :child
tag。在其他情况下,我做了类似的事情,我想要的标签与猴子往往是兄弟姐妹,或者与 wicket:child
标签相距甚远。
我真的很想do是允许孩子更改父级的类属性 - 是否有另一种方法来执行此操作?为什么不能在另一个Wicket页面组件中嵌套子页面?
首先,它与无关实际上是设置属性,但在容器中放置< wicket:child>
。现在设想如果 ChildPage
是一个面板
,你的 ParentPage
看起来像?它将包含一行说 main.add(new ChildPanel())
的行。这就是 main
组件知道它在呈现时应该调用你的子面板的呈现方法。 但与继承是不同的。您的主要
组件无法知道< wicket:child>
应该解析为什么。标记你的 main
container transparent告诉Wicket询问父组件(也就是你的页面组件)来解析并渲染它。
In Wicket 1.4, I'm trying to allow child pages to alter a CSS class on a tag in the parent page, which I do all the time. What is odd about this case is that the tag I want to target wraps the child page markup. Here's a simplified snip 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 blows up because it appears the HTML from the child loads, but not the java. (If I remove the wicket:id and java code on div#main
, all is well.)
Note that the tag on the parent that I want to manipulate from the child is actually wrapping the wicket:child
tag. In other cases I have done something similar, the tags I want to monkey with tend to be siblings or otherwise distant to the wicket:child
tag.
All I really want to do is allow the child to change the class attribute on the parent - is there another way to do this? Why can't a child page be nested under another Wicket page component?
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.
这篇关于wicket:child标签可以嵌套在页面上的另一个组件下吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!