@FunctionalInterface public interface IAjaxRegionMarkupIdProvider extends IClusterable
Component.getMarkupId()
is used.
This mixin is useful when behaviors write directly to the response. Lets examine a simple behavior that wraps the component in a paragraph tag:
class PB extends Behavior { public void beforeRender(Component c) { c.getResponse().write("<p>"); } public void afterRender(Component c) { c.getResponse().write("</p>"); } }If we add this behavior to a
TextField
the generated markup will be:
<p><input wicket:id="name" type="text"></p>If we then update this
TextField
via ajax the generated markup will erroneously be:
<p><p><input wicket:id="name" type="text"></p></p>Notice the doubling of the
<p>
tags. This is happening because every ajax render the
input field is replaced with the markup that contains the input field surrounded by paragraph
tags.
To fix this we can modify our behavior as follows:
class PB extends Behavior implements IAjaxRegionMarkupIdProvider { public void beforeRender(Component c) { c.getResponse().write("<p id='" + c.getMarkupId() + "_p'>"); } public void afterRender(Component c) { c.getResponse().write("</p>"); } public String getAjaxRegionMarkupId(Component component) { return component.getMarkupId() + "_p"; } }Now, the ajax update will properly replace the markup region that includes the paragraph tags with the generated markup.
In the rare case that Component
needs to implement this interface the component
argument of the getAjaxRegionMarkupId(Component)
method can be safely ignored because it
will be the component itself.
Modifier and Type | Method and Description |
---|---|
String |
getAjaxRegionMarkupId(Component component) |
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.