Class AjaxRequestHandler
- java.lang.Object
-
- org.apache.wicket.core.request.handler.AbstractPartialPageRequestHandler
-
- org.apache.wicket.ajax.AjaxRequestHandler
-
- All Implemented Interfaces:
AjaxRequestTarget,IPageClassRequestHandler,IPageRequestHandler,IPartialPageRequestHandler,org.apache.wicket.request.ILoggableRequestHandler,org.apache.wicket.request.IRequestHandler
public class AjaxRequestHandler extends AbstractPartialPageRequestHandler implements AjaxRequestTarget
A request target that produces ajax response envelopes used on the client side to update component markup as well as evaluate arbitrary javascript.A component whose markup needs to be updated should be added to this target via AjaxRequestTarget#add(Component) method. Its body will be rendered and added to the envelope when the target is processed, and refreshed on the client side when the ajax response is received.
It is important that the component whose markup needs to be updated contains an id attribute in the generated markup that is equal to the value retrieved from Component#getMarkupId(). This can be accomplished by either setting the id attribute in the html template, or using an attribute modifier that will add the attribute with value Component#getMarkupId() to the tag ( such as MarkupIdSetter )
Any javascript that needs to be evaluated on the client side can be added using AjaxRequestTarget#append/prependJavaScript(String). For example, this feature can be useful when it is desirable to link component update with some javascript effects.
The target provides a listener interface
AjaxRequestTarget.IListenerthat can be used to add code that responds to various target events by adding listeners viaaddListener(AjaxRequestTarget.IListener)- Since:
- 1.2
- Author:
- Igor Vaynberg (ivaynberg), Eelco Hillenius
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.wicket.ajax.AjaxRequestTarget
AjaxRequestTarget.IJavaScriptResponse, AjaxRequestTarget.IListener, AjaxRequestTarget.ITargetRespondListener
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanlistenersFrozenprotected booleanrespondersFrozensee https://issues.apache.org/jira/browse/WICKET-3564
-
Constructor Summary
Constructors Constructor Description AjaxRequestHandler(Page page)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(AjaxRequestTarget.IListener listener)Adds a listener to this targetvoiddetach(org.apache.wicket.request.IRequestCycle requestCycle)booleanequals(Object obj)Collection<? extends Component>getComponents()Returns an unmodifiable collection of all components added to this targetStringgetLastFocusedElementId()Returns the HTML id of the last focused element.PageLogDatagetLogData()PartialPageUpdategetUpdate()inthashCode()voidregisterRespondListener(AjaxRequestTarget.ITargetRespondListener listener)Register the given respond listener.voidrespond(org.apache.wicket.request.IRequestCycle requestCycle)StringtoString()-
Methods inherited from class org.apache.wicket.core.request.handler.AbstractPartialPageRequestHandler
add, add, addChildren, appendJavaScript, focusComponent, getHeaderResponse, getPage, getPageClass, getPageId, getPageParameters, getRenderCount, isPageInstanceCreated, prependJavaScript
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.ajax.AjaxRequestTarget
getPage
-
Methods inherited from interface org.apache.wicket.core.request.handler.IPageClassRequestHandler
getPageClass, getPageParameters
-
Methods inherited from interface org.apache.wicket.core.request.handler.IPageRequestHandler
getPageId, getRenderCount, isPageInstanceCreated
-
Methods inherited from interface org.apache.wicket.core.request.handler.IPartialPageRequestHandler
add, add, addChildren, appendJavaScript, focusComponent, getHeaderResponse, prependJavaScript
-
-
-
-
Field Detail
-
respondersFrozen
protected transient boolean respondersFrozen
see https://issues.apache.org/jira/browse/WICKET-3564
-
listenersFrozen
protected transient boolean listenersFrozen
-
-
Constructor Detail
-
AjaxRequestHandler
public AjaxRequestHandler(Page page)
Constructor- Parameters:
page- the currently active page
-
-
Method Detail
-
addListener
public void addListener(AjaxRequestTarget.IListener listener) throws IllegalStateException
Description copied from interface:AjaxRequestTargetAdds a listener to this target- Specified by:
addListenerin interfaceAjaxRequestTarget- Throws:
IllegalStateException- ifAjaxRequestTarget.IListener's events are currently being fired or have both been fired already
-
getUpdate
public PartialPageUpdate getUpdate()
- Specified by:
getUpdatein classAbstractPartialPageRequestHandler
-
getComponents
public final Collection<? extends Component> getComponents()
Description copied from interface:IPartialPageRequestHandlerReturns an unmodifiable collection of all components added to this target- Specified by:
getComponentsin interfaceIPartialPageRequestHandler- Returns:
- unmodifiable collection of all components added to this target
-
detach
public void detach(org.apache.wicket.request.IRequestCycle requestCycle)
- Specified by:
detachin interfaceorg.apache.wicket.request.IRequestHandler- See Also:
IRequestHandler.detach(org.apache.wicket.request.IRequestCycle)
-
equals
public boolean equals(Object obj)
- Overrides:
equalsin classObject- See Also:
Object.equals(java.lang.Object)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classObject- See Also:
Object.hashCode()
-
registerRespondListener
public void registerRespondListener(AjaxRequestTarget.ITargetRespondListener listener)
Description copied from interface:AjaxRequestTargetRegister the given respond listener. The listener'sAjaxRequestTarget.ITargetRespondListener.onTargetRespond(org.apache.wicket.ajax.AjaxRequestTarget)method will be invoked when theAjaxRequestTargetstarts to respond.- Specified by:
registerRespondListenerin interfaceAjaxRequestTarget
-
respond
public final void respond(org.apache.wicket.request.IRequestCycle requestCycle)
- Specified by:
respondin interfaceorg.apache.wicket.request.IRequestHandler- See Also:
IRequestHandler.respond(org.apache.wicket.request.IRequestCycle)
-
toString
public String toString()
- Overrides:
toStringin classObject- See Also:
Object.toString()
-
getLastFocusedElementId
public String getLastFocusedElementId()
Description copied from interface:AjaxRequestTargetReturns the HTML id of the last focused element.- Specified by:
getLastFocusedElementIdin interfaceAjaxRequestTarget- Returns:
- the markup id of the focused element in the browser
-
getLogData
public PageLogData getLogData()
- Specified by:
getLogDatain interfaceorg.apache.wicket.request.ILoggableRequestHandler
-
-