From Documentation

Jump to: navigation, search



Here we describe 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.


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.

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


Start Execution in JSF 2 ActionListener

In JSF 2.0 developers can initiate Ajax request using jsf.ajax.request [1] For e.g.

   <h:commandButton id="save" value="Save"
    onclick="jsf.ajax.request(this, event, {execute:'@all'}); return false;" actionListener="${myBean.saveDetails}">

and in your ActionListener

public class MyBean {

   public void saveDetails(ActionEvent e)  throws IOException {

      ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
      ServletContext svlctx = (ServletContext) ec.getContext();
      HttpServletRequest request = (HttpServletRequest) ec.getRequest();
      HttpServletResponse response = (HttpServletResponse) ec.getResponse();
      Component comp = getComponent();
      Bridge bridge = Bridge.start(svlctx, request, response,comp.getDesktop());
      try {
              // update ZK component(s) state here
              //comp.appendChild(new SomethingElse()); ...

              //Send back bridge.getResult() with the response writer (eval)
              PartialResponseWriter responseWriter =
      } finally {

  private Component getComponent() {
      //locate the component that you want to handle

  1. For more information on jsf.ajax.request read official JSF Javascript docs for jsf.ajax.

Version History

Last Update : 2012/10/31

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

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