Start Execution in Foreign Ajax Channel"

From Documentation
Line 12: Line 12:
 
= Example =
 
= Example =
  
Starting an execution in a foreign Ajax channel is straightforward: invoke <javadoc method="start(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.zkoss.zk.ui.Desktop)">org.zkoss.zkplus.embed.Bridge</javadoc>. Then, you are allowed to access the components, post events and do anything you like. At the end, you invoke <javadoc method="getResult()">org.zkoss.zkplus.embed.Bridge</javadoc> to retrieve the JavaScript code snippet and send it back to the client to execute. Finally, you invoke <javadoc method="getResult()">org.zkoss.zkplus.embed.Bridge</javadoc> to close the execution.
+
== Start Execution in JSF 2 Client Behaviors ==
 
 
 
For example, with JSF 2, you could do as follows.
 
For example, with JSF 2, you could do as follows.
  
Line 25: Line 24:
 
     HttpServletResponse response = (HttpServletRersponse)ec.getResponse();
 
     HttpServletResponse response = (HttpServletRersponse)ec.getResponse();
  
Component comp = getComponent();
+
    Component comp = getComponent();
 
     Bridge bridge = Bridge.start(svlctx, request, response, comp.getDesktop());
 
     Bridge bridge = Bridge.start(svlctx, request, response, comp.getDesktop());
 
     try {
 
     try {

Revision as of 05:02, 16 September 2010


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

Start Execution in JSF 2 Client Behaviors

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.