Package org.apache.wicket.ajax
Interface IAjaxRegionMarkupIdProvider
-
- All Superinterfaces:
IClusterable
,Serializable
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface IAjaxRegionMarkupIdProvider extends IClusterable
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 thenComponent.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 aTextField
the generated markup will be:<p><input wicket:id="name" type="text"></p>
If we then update thisTextField
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 thecomponent
argument of thegetAjaxRegionMarkupId(Component)
method can be safely ignored because it will be the component itself.- Author:
- Igor Vaynberg (ivaynberg)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
getAjaxRegionMarkupId(Component component)
-
-
-
Method Detail
-
getAjaxRegionMarkupId
String getAjaxRegionMarkupId(Component component)
- Parameters:
component
-- Returns:
- the id of the markup region that will be updated via ajax.
-
-