Start Execution in Foreign Ajax Channel

From Documentation


Start Execution in Foreign Ajax Channel


Employment/Purpose

Here describes how to start a ZK execution in a foreign Ajax channel. For example, JSF 2 allows developers to send back JavaScript code to update the browser in JSF's Ajax channel[1].


  1. For more information, please refer to Introducing JSF 2 Client Behaviors

Example

Starting an execution in a foreign Ajax channel is straightforward: invoke Bridge.start(ServletContext, HttpServletRequest, HttpServletResponse, Desktop). Then, you are allowed to access the components, post events and do anything you like. At the end, you invoke Bridge.getResult() to retrieve the JavaScript code snippet and send it back to the client to execute. Finally, you invoke Bridge.getResult() to close the execution.

For example, with JSF 2, you could do as follows.

<syntax lang="java"> public class MyCustomBehavior extends ClientBehaviorBase {

 @Override
 public String getScript(ClientBehaviorContext bc) {
   ExternalContext ec = bc.getFacesContext().getExternalContext();
   ServletContext svlctx = (ServletContext)ec.getContext();
   HttpServletRequest request = (HttpServletRequest)ec.getRequest();
   HttpServletResponse response = (HttpServletRersponse)ec.getResponse();

Component comp = getComponent();

   Bridge bridge = Bridge.start(svlctx, request, response, comp.getDesktop());
   try {
     //...do whatever you want
     comp.appendChild(new Label("custom behavior triggered"));
     return bridge.getResult();
   } finally {
     bridge.close();
   }
 }
 private Component getComponent() {
   //locate the component that you want to handle
 }

} </syntax>

Version History

Version Date Content
5.0.5 September 2010 Bridge was introduced to simplify the starting of an execution in foreign Ajax channel



Last Update : 2010/09/16

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.