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.

Bridge

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.close() to close the execution.

<syntax lang="java"> Bridge bridge = Bridge.start(svlctx, request, response, desktop); try {

   //execution started, do whatever you want
   String jscode = bridge.getResult();
   //send jscode back with the foreign Ajax channel.

} finally {

   bridge.close(); //end of execution and cleanup

} </syntax>

Example

Start Execution in JSF 2 Client Behaviors

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

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


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

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.