Class AjaxRequestHandler
- java.lang.Object
-
- org.apache.wicket.core.request.handler.AbstractPartialPageRequestHandler
-
- org.apache.wicket.ajax.AjaxRequestHandler
-
- All Implemented Interfaces:
AjaxRequestTarget
,IPageClassRequestHandler
,IPageRequestHandler
,IPartialPageRequestHandler
,ILoggableRequestHandler
,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.IListener
that 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 boolean
listenersFrozen
protected boolean
respondersFrozen
see 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 void
addListener(AjaxRequestTarget.IListener listener)
Adds a listener to this targetvoid
detach(IRequestCycle requestCycle)
This method is called at the end of a request cycle to indicate that processing is done and that cleaning up of the subject(s) of this target may be done.boolean
equals(Object obj)
Collection<? extends Component>
getComponents()
Returns an unmodifiable collection of all components added to this targetString
getLastFocusedElementId()
Returns the HTML id of the last focused element.PageLogData
getLogData()
Returns the collected log data for this request handler and should never throw an exception.PartialPageUpdate
getUpdate()
int
hashCode()
void
registerRespondListener(AjaxRequestTarget.ITargetRespondListener listener)
Register the given respond listener.void
respond(IRequestCycle requestCycle)
Generates a response.String
toString()
-
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:AjaxRequestTarget
Adds a listener to this target- Specified by:
addListener
in interfaceAjaxRequestTarget
- Throws:
IllegalStateException
- ifAjaxRequestTarget.IListener
's events are currently being fired or have both been fired already
-
getUpdate
public PartialPageUpdate getUpdate()
- Specified by:
getUpdate
in classAbstractPartialPageRequestHandler
-
getComponents
public final Collection<? extends Component> getComponents()
Description copied from interface:IPartialPageRequestHandler
Returns an unmodifiable collection of all components added to this target- Specified by:
getComponents
in interfaceIPartialPageRequestHandler
- Returns:
- unmodifiable collection of all components added to this target
-
detach
public void detach(IRequestCycle requestCycle)
Description copied from interface:IRequestHandler
This method is called at the end of a request cycle to indicate that processing is done and that cleaning up of the subject(s) of this target may be done.- Specified by:
detach
in interfaceIRequestHandler
- Parameters:
requestCycle
- the current request cycle- See Also:
IRequestHandler.detach(org.apache.wicket.request.IRequestCycle)
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classObject
- See Also:
Object.equals(java.lang.Object)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classObject
- See Also:
Object.hashCode()
-
registerRespondListener
public void registerRespondListener(AjaxRequestTarget.ITargetRespondListener listener)
Description copied from interface:AjaxRequestTarget
Register the given respond listener. The listener'sAjaxRequestTarget.ITargetRespondListener.onTargetRespond(org.apache.wicket.ajax.AjaxRequestTarget)
method will be invoked when theAjaxRequestTarget
starts to respond.- Specified by:
registerRespondListener
in interfaceAjaxRequestTarget
-
respond
public final void respond(IRequestCycle requestCycle)
Description copied from interface:IRequestHandler
Generates a response.- Specified by:
respond
in interfaceIRequestHandler
- Parameters:
requestCycle
- the current request cycle- See Also:
IRequestHandler.respond(org.apache.wicket.request.IRequestCycle)
-
toString
public String toString()
- Overrides:
toString
in classObject
- See Also:
Object.toString()
-
getLastFocusedElementId
public String getLastFocusedElementId()
Description copied from interface:AjaxRequestTarget
Returns the HTML id of the last focused element.- Specified by:
getLastFocusedElementId
in interfaceAjaxRequestTarget
- Returns:
- the markup id of the focused element in the browser
-
getLogData
public PageLogData getLogData()
Description copied from interface:ILoggableRequestHandler
Returns the collected log data for this request handler and should never throw an exception. This method is never called before the request handler is detached.- Specified by:
getLogData
in interfaceILoggableRequestHandler
- Returns:
- The collected log data.
-
-