Package org.ajax4jsf.javascript

Examples of org.ajax4jsf.javascript.JSFunctionDefinition


    if (oncomplete != null) {
      options.put("onbeforedomupdate", oncomplete);
    }
    ajaxFunction.addParameter(options);

    JSFunctionDefinition function = new JSFunctionDefinition("uid");
    function.addParameter("formId");
    function.addParameter("event");
    function.addToBody(ajaxFunction.toScript());

    return function.toScript();
  }
View Full Code Here


   * @return
   * @throws IOException
   */
  public String getFileSizeScript(FacesContext context, UIComponent component)
      throws IOException {
    JSFunctionDefinition oncomplete = new JSFunctionDefinition();
    oncomplete.addParameter("request");
    oncomplete.addParameter("event");
    oncomplete.addParameter("data");
    StringBuffer body = new StringBuffer("$('");
    body.append(component.getClientId(context));
    body.append("').component.getFileSize(data);");
    oncomplete.addToBody(body);
    return getActionScript(context, component, "progress", oncomplete);

  }
View Full Code Here

  public String getScriptContribution(FacesContext context, UIComponent component) {
    StringBuffer result = new StringBuffer();

    result.append(".drop = ");

    JSFunctionDefinition definition = new JSFunctionDefinition();
    definition.addParameter("event");
    definition.addParameter("drag");

    Map requestOpts = AjaxRendererUtils.buildEventOptions(context, component);
    definition.addToBody("var options = ").addToBody(ScriptUtils.toScript(requestOpts)).addToBody(";");
    definition.addToBody("options.parameters['" + DROP_TARGET_ID + "'] = '" + component.getClientId(context) + "';");
    //TODO nick - remove as legacy
    definition.addToBody("Object.extend(options.parameters,drag.getParameters());");
    definition.addToBody("var dzOptions = this.getDropzoneOptions(); if (dzOptions.ondrop) { if (!dzOptions.ondrop.call(this, event)) return; };");
   
    JSFunction dropFunction = AjaxRendererUtils.buildAjaxFunction(component, context);
    dropFunction.addParameter(new JSReference("options"));
   
    definition.addToBody(dropFunction.toScript()).addToBody(";");
    definition.appendScript(result);
    result.append(";");

    return result.toString();
  }
View Full Code Here

    return null;
  }

  public String getFunction(FacesContext context, UIAjaxFunction component) {
    StringBuffer script = new StringBuffer(component.getName()).append("=");
    JSFunctionDefinition func = new JSFunctionDefinition();
    //func.setName(component.getName());
    // Create AJAX Submit function.
    JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(
        component, context,AjaxRendererUtils.AJAX_FUNCTION_NAME);
    Map options = AjaxRendererUtils.buildEventOptions(context, component);
    Map parameters = (Map) options.get("parameters");
    if (null == parameters) {
      parameters = new HashMap();
      options.put("parameters", parameters);
    }
    ajaxFunction.addParameter(JSReference.NULL);
    ajaxFunction.addParameter(options);
    // Fill parameters.
    for (Iterator it = component.getChildren().iterator(); it.hasNext();) {
      UIComponent child = (UIComponent) it.next();
      if (child instanceof UIParameter) {
        UIParameter parameter = ((UIParameter) child);
        String name = parameter.getName();
        func.addParameter(name);
        // Put parameter name to AJAX.Submit parameter, with default value.
        JSReference reference = new JSReference(name);
        if (null != parameter.getValue()) {
          reference = new JSReference(name + "||"
              + ScriptUtils.toScript(parameters.get(name)));

        }
        // Replace parameter value to reference.
        parameters.put(name, reference);
      }
    }
    func.addToBody(ajaxFunction.toScript());
    func.appendScript(script);
    return script.toString();
  }
View Full Code Here

    public String getItemsTextAsJSArray(FacesContext context, UIComponent component, List items) {
      return ScriptUtils.toScript(items);
    }

    public String getAsEventHandler(FacesContext context, UIComponent component, String attributeName) {
  JSFunctionDefinition script = getUtils().getAsEventHandler(context, component, attributeName, null)
  return ScriptUtils.toScript(script);
    }
View Full Code Here

      }
      options.put("affected", areasIds);
    }
    String oncomplete = getAjaxOncomplete(uiComponent);
    if (null != oncomplete) {
      JSFunctionDefinition function = new JSFunctionDefinition();
      function.addParameter("request");
      function.addParameter("event");
      function.addParameter("data");
      function.addToBody(oncomplete);

      options.put(ONCOMPLETE_ATTR_NAME, function);
    }
   
    String beforeupdate = getAjaxOnBeforeDomUpdate(uiComponent);
    if (null != beforeupdate) {
      JSFunctionDefinition function = new JSFunctionDefinition();
      function.addParameter("request");
      function.addParameter("event");
      function.addParameter("data");
      function.addToBody(beforeupdate);

      options.put(ONBEFOREDOMUPDATE_ATTR_NAME, function);
    }
   
   
View Full Code Here

      }
    }
  }
  public void addEventHandler(String event, String handler) {
    if (event != null &&  handler != null) {
      JSFunctionDefinition functionDefinition =
        new JSFunctionDefinition("event");
     
      functionDefinition.addToBody(handler);
      functionDefinition.addToBody(";return true;");
      addEventHandler(event, functionDefinition);
    }
  }
View Full Code Here

        target.append(AJAX).append(':');
        appendAjaxFunction(target, ajaxScript);
    }

    protected void appendAjaxFunction(Appendable target, String ajaxScript) throws IOException {
        JSFunctionDefinition ajaxFunction = new JSFunctionDefinition(EVENT, CLIENT_ID);
        ajaxFunction.addToBody(ajaxScript);
        ajaxFunction.appendScript(target);
    }
View Full Code Here

        writer.write(function.toString());
    }

    public JSFunctionDefinition getSubmitFunction(FacesContext facesContext, UIComponent component) {
        JSFunctionDefinition definition = new JSFunctionDefinition(JSReference.EVENT, new JSReference("element"),
            new JSReference("data"));

        AjaxFunction function = AjaxRendererUtils.buildAjaxFunction(facesContext, component);

        Map<String, Object> parameters = function.getOptions().getParameters();
        parameters.put(component.getClientId(facesContext) + ":page", new JSLiteral("data.page"));

        definition.addToBody(function.toScript());
        return definition;
    }
View Full Code Here

        handlersChain.addAjaxSubmitFunction();

        String handler = handlersChain.toScript();

        if (handler != null) {
            JSFunctionDefinition timerHandler = new JSFunctionDefinition(JSReference.EVENT);
            timerHandler.addToBody(handler);
            options.put(AbstractPoll.ON_TIMER, timerHandler);
        }
        if (poll.isEnabled()) {
            options.put(ENABLED, true);
        }
View Full Code Here

TOP

Related Classes of org.ajax4jsf.javascript.JSFunctionDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.