org.apache.wicket.ajax
Interface IAjaxRegionMarkupIdProvider
public interface IAjaxRegionMarkupIdProvider
A mixin that allows behaviors and components to override the id of the markup region that will be
updated via ajax. If this mixin is not used then 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 AbstractBehavior
{
public void onBeforeRender(Component c)
{
c.getResponse().write("<p>");
}
public void onComponentRendered(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 AbstractBehavior implements IAjaxRegionMarkupIdProvider
{
public void onBeforeRender(Component c)
{
c.getResponse().write("<p id='" + c.getMarkupId() + "_p'>");
}
public void onComponentRendered(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.
- Author:
- Igor Vaynberg (ivaynberg)
getAjaxRegionMarkupId
String getAjaxRegionMarkupId(Component component)
Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.