|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.wicket.ajax.AjaxRequestHandler
public class AjaxRequestHandler
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 via
addListener(AjaxRequestTarget.IListener)
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.apache.wicket.ajax.AjaxRequestTarget |
|---|
AjaxRequestTarget.AbstractListener, AjaxRequestTarget.IJavaScriptResponse, AjaxRequestTarget.IListener, AjaxRequestTarget.ITargetRespondListener |
| Field Summary | |
|---|---|
protected boolean |
listenersFrozen
|
protected boolean |
respondersFrozen
see https://issues.apache.org/jira/browse/WICKET-3564 |
| Constructor Summary | |
|---|---|
AjaxRequestHandler(Page page)
Constructor |
|
| Method Summary | |
|---|---|
void |
add(Component... components)
Adds components to the list of components to be rendered. |
void |
add(Component component,
String markupId)
Adds a component to the list of components to be rendered |
void |
addChildren(MarkupContainer parent,
Class<?> childCriteria)
Visits all children of the specified parent container and adds them to the target if they are of same type as childCriteria |
void |
addListener(AjaxRequestTarget.IListener listener)
Adds a listener to this target |
void |
appendJavaScript(CharSequence javascript)
Adds javascript that will be evaluated on the client side after components are replaced |
void |
detach(IRequestCycle requestCycle)
|
boolean |
equals(Object obj)
|
void |
focusComponent(Component component)
Sets the focus in the browser to the given component. |
Collection<? extends Component> |
getComponents()
Returns an unmodifiable collection of all components added to this target |
IHeaderResponse |
getHeaderResponse()
Returns the header response associated with current AjaxRequestTarget. |
String |
getLastFocusedElementId()
Returns the HTML id of the last focused element. |
PageLogData |
getLogData()
|
Page |
getPage()
Returns the page. |
Class<? extends IRequestablePage> |
getPageClass()
Returns the page class |
Integer |
getPageId()
Returns the page id. |
PageParameters |
getPageParameters()
|
Integer |
getRenderCount()
Returns the number of times this page has been rendered. |
int |
hashCode()
|
boolean |
isPageInstanceCreated()
Checks if the page instance is already created or if it will be created when IPageRequestHandler.getPage() is called |
void |
prependJavaScript(CharSequence javascript)
Adds javascript that will be evaluated on the client side before components are replaced. |
void |
registerRespondListener(AjaxRequestTarget.ITargetRespondListener listener)
Register the given respond listener. |
void |
respond(IRequestCycle requestCycle)
|
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected transient boolean respondersFrozen
protected transient boolean listenersFrozen
| Constructor Detail |
|---|
public AjaxRequestHandler(Page page)
page - the currently active page| Method Detail |
|---|
public Page getPage()
AjaxRequestTarget
getPage in interface AjaxRequestTargetgetPage in interface IPageRequestHandlerIPageRequestHandler.getPage()
public void addListener(AjaxRequestTarget.IListener listener)
throws IllegalStateException
AjaxRequestTarget
addListener in interface AjaxRequestTargetIllegalStateException - if AjaxRequestTarget.IListener's events are currently being fired or have both been fired
already
public final void addChildren(MarkupContainer parent,
Class<?> childCriteria)
AjaxRequestTargetchildCriteria
addChildren in interface AjaxRequestTargetparent - Must not be null.childCriteria - Must not be null. If you want to traverse all components use ` Component.class as
the value for this argument.public void add(Component... components)
AjaxRequestTarget
add in interface AjaxRequestTargetcomponents - components to be rendered
public void add(Component component,
String markupId)
AjaxRequestTarget
add in interface AjaxRequestTargetcomponent - component to be renderedmarkupId - id of client-side dom element that will be updatedpublic final Collection<? extends Component> getComponents()
AjaxRequestTarget
getComponents in interface AjaxRequestTargetpublic final void focusComponent(Component component)
AjaxRequestTarget
focusComponent in interface AjaxRequestTargetcomponent - The component to get the focus or null.public final void appendJavaScript(CharSequence javascript)
AjaxRequestTargetIf the javascript needs to do something asynchronously (i.e. needs to use window.setTimeout(), for example
to do animations) then the following special syntax may be used: someFunctionName|myJsLogic(someFunctionName);.
Wicket will transform it to: function(someFunctionName){myJsLogic(someFunctionName);} and your code
is responsible to execute someFunctionName() when the asynchronous task is finished. Once someFunctionName
is executed the next appended script will be executed. Important: it is highly recommended to
execute your code in try/finally to make sure someFunctionName is executed even an error happens in
your code, otherwise all following scripts wont be executed.
appendJavaScript in interface AjaxRequestTargetpublic void detach(IRequestCycle requestCycle)
detach in interface IRequestHandlerIRequestHandler.detach(org.apache.wicket.request.IRequestCycle)public boolean equals(Object obj)
equals in class ObjectObject.equals(java.lang.Object)public int hashCode()
hashCode in class ObjectObject.hashCode()public final void prependJavaScript(CharSequence javascript)
AjaxRequestTargetIf the javascript needs to do something asynchronously (i.e. needs to use window.setTimeout(), for example
to do animations) then the following special syntax may be used: someFunctionName|myJsLogic(someFunctionName);.
Wicket will transform it to: function(someFunctionName){myJsLogic(someFunctionName);} and your code
is responsible to execute someFunctionName() when the asynchronous task is finished. Once someFunctionName
is executed the next prepended script will be executed. Important: it is highly recommended to
execute your code in try/finally to make sure someFunctionName is executed even an error happens in
your code, otherwise all following scripts and component replacements wont be made.
prependJavaScript in interface AjaxRequestTargetpublic void registerRespondListener(AjaxRequestTarget.ITargetRespondListener listener)
AjaxRequestTargetAjaxRequestTarget.ITargetRespondListener.onTargetRespond(org.apache.wicket.ajax.AjaxRequestTarget) method will be invoked when
the AjaxRequestTarget starts to respond.
registerRespondListener in interface AjaxRequestTargetpublic final void respond(IRequestCycle requestCycle)
respond in interface IRequestHandlerIRequestHandler.respond(org.apache.wicket.request.IRequestCycle)public String toString()
toString in class ObjectObject.toString()public IHeaderResponse getHeaderResponse()
AjaxRequestTarget
getHeaderResponse in interface AjaxRequestTargetpublic String getLastFocusedElementId()
AjaxRequestTarget
getLastFocusedElementId in interface AjaxRequestTargetpublic Class<? extends IRequestablePage> getPageClass()
IPageClassRequestHandler
getPageClass in interface IPageClassRequestHandlerIPageClassRequestHandler.getPageClass()public Integer getPageId()
IPageRequestHandler
getPageId in interface IPageRequestHandlerIPageRequestHandler.getPageId()public PageParameters getPageParameters()
getPageParameters in interface IPageClassRequestHandlerIPageClassRequestHandler.getPageParameters()public final boolean isPageInstanceCreated()
IPageRequestHandlerIPageRequestHandler.getPage() is called
isPageInstanceCreated in interface IPageRequestHandlertrue iff page instance is already createdpublic final Integer getRenderCount()
IPageRequestHandler
getRenderCount in interface IPageRequestHandlerIRequestablePage.getRenderCount()public PageLogData getLogData()
getLogData in interface ILoggableRequestHandler
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||