|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.ajax.AjaxRequestTarget
public class 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#addComponent(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(org.apache.wicket.ajax.AjaxRequestTarget.IListener)
Nested Class Summary | |
---|---|
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. |
Constructor Summary | |
---|---|
AjaxRequestTarget(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 |
addComponent(Component... components)
Deprecated. use add(Component...) instead |
void |
addComponent(Component component,
String markupId)
Deprecated. use add(Component...) instead |
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)
|
protected String |
encode(CharSequence str)
Encodes a string so it is safe to use inside CDATA blocks |
boolean |
equals(Object obj)
|
void |
focusComponent(Component component)
Sets the focus in the browser to the given component. |
static AjaxRequestTarget |
get()
Static method that returns current AjaxRequestTarget or null of no
AjaxRequestTarget is available. |
Collection<? extends Component> |
getComponents()
Returns an unmodifiable collection of all components added to this target |
protected String |
getEncodingName()
|
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 |
protected boolean |
needsEncoding(CharSequence str)
|
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 |
Constructor Detail |
---|
public AjaxRequestTarget(Page page)
page
- Method Detail |
---|
public Page getPage()
IPageRequestHandler
getPage
in interface IPageRequestHandler
IPageRequestHandler.getPage()
public void addListener(AjaxRequestTarget.IListener listener) throws IllegalStateException
listener
-
IllegalStateException
- if AjaxRequestTarget.IListener
's events are currently being fired or have both been fired
alreadypublic final void addChildren(MarkupContainer parent, Class<?> childCriteria)
childCriteria
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.@Deprecated public void addComponent(Component... components)
add(Component...)
instead
components
- components to be renderedpublic void add(Component... components)
components
- components to be rendered@Deprecated public final void addComponent(Component component, String markupId)
add(Component...)
instead
markupId
- id of client-side dom element that will be updatedcomponent
- component to be renderedpublic final void add(Component component, String markupId) throws IllegalArgumentException, IllegalStateException
markupId
- id of client-side dom element that will be updatedcomponent
- component to be rendered
IllegalArgumentException
- if the component is a Page
or an AbstractRepeater
IllegalStateException
- if the components are currently being rendered, or have already been renderedpublic final Collection<? extends Component> getComponents()
public final void focusComponent(Component component)
component
- The component to get the focus or null.public final void appendJavaScript(CharSequence javascript)
javascript
- public void detach(IRequestCycle requestCycle)
detach
in interface IRequestHandler
IRequestHandler.detach(org.apache.wicket.request.IRequestCycle)
public boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class Object
Object.hashCode()
public final void prependJavaScript(CharSequence javascript)
javascript
- public void registerRespondListener(AjaxRequestTarget.ITargetRespondListener listener)
AjaxRequestTarget.ITargetRespondListener.onTargetRespond(AjaxRequestTarget)
method will be invoked when
the AjaxRequestTarget
starts to respond.
listener
- public final void respond(IRequestCycle requestCycle)
respond
in interface IRequestHandler
IRequestHandler.respond(org.apache.wicket.request.IRequestCycle)
public String toString()
toString
in class Object
Object.toString()
protected String encode(CharSequence str)
str
-
protected String getEncodingName()
protected boolean needsEncoding(CharSequence str)
str
-
public IHeaderResponse getHeaderResponse()
public static AjaxRequestTarget get()
AjaxRequestTarget
or null
of no
AjaxRequestTarget
is available.
AjaxRequestTarget
instance if current request is an Ajax request,
null
otherwise.public String getLastFocusedElementId()
null
if nonepublic Class<? extends IRequestablePage> getPageClass()
IPageClassRequestHandler
getPageClass
in interface IPageClassRequestHandler
IPageClassRequestHandler.getPageClass()
public Integer getPageId()
IPageRequestHandler
getPageId
in interface IPageRequestHandler
IPageRequestHandler.getPageId()
public PageParameters getPageParameters()
getPageParameters
in interface IPageClassRequestHandler
IPageClassRequestHandler.getPageParameters()
public final boolean isPageInstanceCreated()
IPageRequestHandler
IPageRequestHandler.getPage()
is called
isPageInstanceCreated
in interface IPageRequestHandler
true
iff page instance is not yet createdpublic final Integer getRenderCount()
IPageRequestHandler
getRenderCount
in interface IPageRequestHandler
IRequestablePage.getRenderCount()
public PageLogData getLogData()
getLogData
in interface ILoggableRequestHandler
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |