org.apache.wicket.ajax
Interface AjaxRequestTarget

All Superinterfaces:
ILoggableRequestHandler, IPageClassRequestHandler, IPageRequestHandler, IRequestHandler
All Known Implementing Classes:
AjaxRequestHandler, WebSocketRequestHandler

public interface AjaxRequestTarget
extends IPageRequestHandler, ILoggableRequestHandler

Since:
6.0

Nested Class Summary
static class AjaxRequestTarget.AbstractListener
          Empty implementation of an AjaxRequestTarget.IListener useful as a starting point for your own custom listener.
static interface AjaxRequestTarget.IJavaScriptResponse
          An ajax javascript response that allows users to add javascript to be executed on the client side
static interface AjaxRequestTarget.IListener
          An AjaxRequestTarget listener that can be used to respond to various target-related events
static interface AjaxRequestTarget.ITargetRespondListener
          Components can implement this interface to get a notification when AjaxRequestTarget begins to respond.
 
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 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.
 Page getPage()
          Returns the page.
 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.
 
Methods inherited from interface org.apache.wicket.core.request.handler.IPageRequestHandler
getPageId, getRenderCount, isPageInstanceCreated
 
Methods inherited from interface org.apache.wicket.core.request.handler.IPageClassRequestHandler
getPageClass, getPageParameters
 
Methods inherited from interface org.apache.wicket.request.IRequestHandler
detach, respond
 
Methods inherited from interface org.apache.wicket.request.ILoggableRequestHandler
getLogData
 

Method Detail

add

void add(Component component,
         String markupId)
Adds a component to the list of components to be rendered

Parameters:
markupId - id of client-side dom element that will be updated
component - component to be rendered
Throws:
IllegalArgumentException - if the component is a Page or an AbstractRepeater
IllegalStateException - if the components are currently being rendered, or have already been rendered

add

void add(Component... components)
Adds components to the list of components to be rendered.

Parameters:
components - components to be rendered

addChildren

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

Parameters:
parent - 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.

addListener

void addListener(AjaxRequestTarget.IListener listener)
Adds a listener to this target

Parameters:
listener -
Throws:
IllegalStateException - if AjaxRequestTarget.IListener's events are currently being fired or have both been fired already

appendJavaScript

void appendJavaScript(CharSequence javascript)
Adds javascript that will be evaluated on the client side after components are replaced

If 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.

Parameters:
javascript -

prependJavaScript

void prependJavaScript(CharSequence javascript)
Adds javascript that will be evaluated on the client side before components are replaced.

If 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.

Parameters:
javascript -

registerRespondListener

void registerRespondListener(AjaxRequestTarget.ITargetRespondListener listener)
Register the given respond listener. The listener's AjaxRequestTarget.ITargetRespondListener.onTargetRespond(org.apache.wicket.ajax.AjaxRequestTarget) method will be invoked when the AjaxRequestTarget starts to respond.

Parameters:
listener -

getComponents

Collection<? extends Component> getComponents()
Returns an unmodifiable collection of all components added to this target

Returns:
unmodifiable collection of all components added to this target

focusComponent

void focusComponent(Component component)
Sets the focus in the browser to the given component. The markup id must be set. If the component is null the focus will not be set to any component.

Parameters:
component - The component to get the focus or null.

getHeaderResponse

IHeaderResponse getHeaderResponse()
Returns the header response associated with current AjaxRequestTarget. Beware that only renderOnDomReadyJavaScript and renderOnLoadJavaScript can be called outside the renderHeader(IHeaderResponse response) method. Calls to other render** methods will result in the call failing with a debug-level log statement to help you see why it failed.

Returns:
header response

getLastFocusedElementId

String getLastFocusedElementId()
Returns the HTML id of the last focused element.

Returns:
markup id of last focused element, null if none

getPage

Page getPage()
Returns the page. Be aware that the page can be instantiated if this wasn't the case already.

Specified by:
getPage in interface IPageRequestHandler
Returns:
page instance


Copyright © 2006–2017 Apache Software Foundation. All rights reserved.