wicket.ajax
Class AjaxRequestTarget

java.lang.Object
  extended by wicket.ajax.AjaxRequestTarget
All Implemented Interfaces:
IRequestTarget

public class AjaxRequestTarget
extends java.lang.Object
implements IRequestTarget

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 evaluater on the client side can be added using AjaxRequestTarget#addJavascript(String). For example, this feature can be useful when it is desirable to link component update with some javascript effects.

Since:
1.2
Author:
Igor Vaynberg (ivaynberg), Eelco Hillenius

Constructor Summary
AjaxRequestTarget()
          Constructor
 
Method Summary
 void addComponent(Component component)
          Adds a component to the list of components to be rendered
 void addComponent(Component component, java.lang.String markupId)
          Adds a component to the list of components to be rendered
 void addJavascript(java.lang.String javascript)
          Deprecated. use appendJavascript(String javascript) instead
 void appendJavascript(java.lang.String javascript)
          Adds javascript that will be evaluated on the client side after components are replaced
 void detach(RequestCycle requestCycle)
          This method is alled on 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.
protected  java.lang.String encode(java.lang.String str)
          Encodes a string so it is safe to use inside CDATA blocks
 boolean equals(java.lang.Object obj)
           
protected  java.lang.String getEncodingName()
           
 java.lang.Object getLock(RequestCycle requestCycle)
          Gets the lock to be used for synchronization.
 int hashCode()
           
protected  boolean needsEncoding(java.lang.String str)
           
 void prependJavascript(java.lang.String javascript)
          Adds javascript that will be evaluated on the client side before components are replaced
 void respond(RequestCycle requestCycle)
          Generates a response.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AjaxRequestTarget

public AjaxRequestTarget()
Constructor

Method Detail

addComponent

public final void addComponent(Component component)
Adds a component to the list of components to be rendered

Parameters:
component - component to be rendered

addComponent

public final void addComponent(Component component,
                               java.lang.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

addJavascript

public final void addJavascript(java.lang.String javascript)
Deprecated. use appendJavascript(String javascript) instead

Adds javascript that will be evaluated on the client side after components are replaced

Parameters:
javascript -

appendJavascript

public final void appendJavascript(java.lang.String javascript)
Adds javascript that will be evaluated on the client side after components are replaced

Parameters:
javascript -

detach

public void detach(RequestCycle requestCycle)
Description copied from interface: IRequestTarget
This method is alled on 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 interface IRequestTarget
Parameters:
requestCycle - the current request cycle
See Also:
IRequestTarget.detach(wicket.RequestCycle)

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

getLock

public java.lang.Object getLock(RequestCycle requestCycle)
Description copied from interface: IRequestTarget
Gets the lock to be used for synchronization.

Specified by:
getLock in interface IRequestTarget
Parameters:
requestCycle - the current request cycle
Returns:
Any lock to be used to synchronize this target or null if no synchronization is needed.
See Also:
IRequestTarget.getLock(RequestCycle)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

prependJavascript

public final void prependJavascript(java.lang.String javascript)
Adds javascript that will be evaluated on the client side before components are replaced

Parameters:
javascript -

respond

public final void respond(RequestCycle requestCycle)
Description copied from interface: IRequestTarget
Generates a response.

Specified by:
respond in interface IRequestTarget
Parameters:
requestCycle - the current request cycle
See Also:
IRequestTarget.respond(wicket.RequestCycle)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

encode

protected java.lang.String encode(java.lang.String str)
Encodes a string so it is safe to use inside CDATA blocks

Parameters:
str -
Returns:
encoded string

getEncodingName

protected java.lang.String getEncodingName()
Returns:
name of encoding used to possibly encode the contents of the CDATA blocks

needsEncoding

protected boolean needsEncoding(java.lang.String str)
Parameters:
str -
Returns:
true if string needs to be encoded, false otherwise


Copyright © 2004-2008 Wicket developers. All Rights Reserved.