Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Won't Fix
-
1.3.0-rc1
-
None
-
None
Description
There is always some part of a page that we need to replace its content with some new block of html markup retrieved from an ajax call. What i am currently doing is using a fragment to represent the original block of html, like this:
<span wicket:id="container"></span>
<wicket:fragment wicket:id="original-content-of-container">
original contents that can contain nested component like <span wicket:id="nested-component"></span>
<wicket:fragment>
<a wicket:id="ReplaceContainer">Click me to replace container's content with a new one</a>
in the java code:
public ThePage(){
Fragment container = new Fragment("container", "original-content-of-container", this);
container.setOutputMarkupId(true);
container.add(new Label("nested-component", "nested component content"));
add(container);
add(new AjaxLink("ReplaceContainer"){
onClick(target)
}
}
This works fine. The container can later be replaced by another component such as a panel. But requires an additional fragment to be defined and disturbs the structure of the markup. IMO, the natural way is to just use a WebMarkupContainer to render the original content, like this:
<span wicket:id="container">
original contents that can contain nested component like <span wicket:id="nested-component"></span>
</span>
<a wicket:id="ReplaceContainer">Click me to replace container's content with a new one</a>
in the java code:
public ThePage(){
WebMarkupContainer container = new WebMarkupContainer("container");
container.setOutputMarkupId(true);
container.add(new Label("nested-component", "nested component content"));
add(container);
add(new AjaxLink("ReplaceContainer"){
onClick(target){ NewPanel newContainer = new NewPanel("container"); newContainer.add(...new nested components...); newContainer.setOutputMarkupId(true); ThePage.this.addOrReplace(newContainer); target.addComponent(newContainer); }
}
}
The above codes render the original container successfully. But the replace action only works if the original container does not have any nested components. When it has some, wicket throws an exception says : "close tag not found for tag: <span id="container1" wicket:id="container"> ..."