|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface AjaxBehavior
AjaxBehavior extends the basic Behavior functionality to allow Controls to handle and process incoming Ajax requests.
To handle an Ajax request, AjaxBehavior exposes the listener method:onAction
.
The onAction method returns an ActionResult that is rendered back
to the browser.
Before Click invokes the onAction method it checks whether the request
is targeted at the AjaxBehavior by invoking the method
Behavior.isAjaxTarget()
.
Click will only invoke onAction if isAjaxTarget returns true.
Method Summary | |
---|---|
boolean |
isAjaxTarget(Context context)
Return true if the behavior is the request target, false otherwise. |
ActionResult |
onAction(Control source)
This method can be implemented to handle and respond to an Ajax request. |
Methods inherited from interface org.apache.click.Behavior |
---|
preDestroy, preRenderHeadElements, preResponse |
Method Detail |
---|
ActionResult onAction(Control source)
public void onInit() { ActionLink link = new ActionLink("link"); link.addBehaior(new DefaultAjaxBehavior() { public ActionResult onAction(Control source) { ActionResult result = new ActionResult("<h1>Hello world</h1>", ActionResult.HTML); return result; } }); }
source
- the control the behavior is attached to
boolean isAjaxTarget(Context context)
onAction(org.apache.click.Control)
method should be called in
response to a request.
By exposing this method through the Behavior interface it provides
implementers with fine grained control over whether the Behavior's
onAction(org.apache.click.Control)
method should be invoked or not.
Below is an example implementation:
public CustomBehavior implements Behavior { private String eventType; public CustomBehavior(String eventType) { // The event type of the behavior super(eventType); } public boolean isAjaxTarget(Context context) { // Retrieve the eventType parameter from the incoming request String eventType = context.getRequestParameter("type"); // Check if this Behavior's eventType matches the request // "type" parameter return StringUtils.equalsIgnoreCase(this.eventType, eventType); } public ActionResult onAction(Control source) { // If isAjaxTarget returned true, the onAction method will be // invoked ... } }
context
- the request context
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |