Package org.ajax4jsf.javascript

Examples of org.ajax4jsf.javascript.JSFunction


    String id = table.getClientId(context);

    //Ajax submission requires scripts
    setRequiresScripts(context);
   
    JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(table, context);
    Map<String, Object> eventOptions = AjaxRendererUtils.buildEventOptions(context, table, true);
   
   
    @SuppressWarnings("unchecked")
    Map<String, Object> parameters =
        (Map<String, Object>) eventOptions.get("parameters");
   
    parameters.put(id, SORT_FILTER_PARAMETER);
    if (sortable) {
      parameters.put(SORT_FILTER_PARAMETER, column.getClientId(context));
    }
    ajaxFunction.addParameter(eventOptions);
   
    StringBuffer buffer = new StringBuffer();
    ajaxFunction.appendScript(buffer);
   
    return buffer.toString();
  }
View Full Code Here


    public JSFunctionDefinition createShowMenuEventFunction() {
        JSFunctionDefinition definition = new JSFunctionDefinition();
        definition.addParameter("event");
        definition.addParameter("columnId");
        definition.addParameter("menuId");
        JSFunction invocation = new JSFunction(
                "Richfaces.componentControl.performOperation");
        invocation.addParameter(new JSReference("event"));
        invocation.addParameter(new JSReference("event.type"));
        invocation.addParameter(new JSReference("menuId"));
        invocation.addParameter("show");
        // invocation.addParameter(new JSReference("{'columnId':columnId}"));
        invocation.addParameter(new JSReference("{}"));
        invocation.addParameter(Boolean.FALSE);
        definition.addToBody(invocation.toScript()).addToBody(";\n");
        return definition;
    }
View Full Code Here

  public void writeSubmitFunction(FacesContext context, UICalendar calendar)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();

    JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(calendar,
        context, AjaxRendererUtils.AJAX_FUNCTION_NAME);
    ajaxFunction.addParameter(JSReference.NULL);
    Map<String, Object> options = AjaxRendererUtils.buildEventOptions(context, calendar);
    options.put("calendar", JSReference.THIS);
    boolean isSingle = ((Boolean) calendar.getAttributes()
        .get("ajaxSingle")).booleanValue();
    if (isSingle) {
      options.put("single", JSReference.TRUE);
    }

    String oncomplete = AjaxRendererUtils.getAjaxOncomplete(calendar);
    JSFunctionDefinition oncompleteDefinition = new JSFunctionDefinition();
    oncompleteDefinition.addParameter("request");
    oncompleteDefinition.addParameter("event");
    oncompleteDefinition.addParameter("data");
    oncompleteDefinition.addToBody("this.calendar.load(data, true);");
    if (oncomplete != null) {
      oncompleteDefinition.addToBody(oncomplete);
    }

    options.put("oncomplete", oncompleteDefinition);
    JSReference requestValue = new JSReference("requestValue");
    ajaxFunction.addParameter(options);
    JSFunctionDefinition definition = new JSFunctionDefinition();
    definition.addParameter(requestValue);
    definition.addToBody(ajaxFunction);
    writer.write(definition.toScript());
  }
View Full Code Here

  }

  public static Object formatDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    JSFunction result = new JSFunction("new Date");
    result.addParameter(Integer.valueOf(calendar.get(Calendar.YEAR)));
    result.addParameter(Integer.valueOf(calendar.get(Calendar.MONTH)));
    result.addParameter(Integer.valueOf(calendar.get(Calendar.DATE)));

    return result;
  }
View Full Code Here

  }

  public static Object formatSelectedDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    JSFunction result = new JSFunction("new Date");
    result.addParameter(Integer.valueOf(calendar.get(Calendar.YEAR)));
    result.addParameter(Integer.valueOf(calendar.get(Calendar.MONTH)));
    result.addParameter(Integer.valueOf(calendar.get(Calendar.DATE)));
    result
        .addParameter(Integer.valueOf(calendar
            .get(Calendar.HOUR_OF_DAY)));
    result.addParameter(Integer.valueOf(calendar.get(Calendar.MINUTE)));
    result.addParameter(new Integer(0));
    return result;
  }
View Full Code Here

  }

  @Override
  protected String getLayerScript(FacesContext context, UIComponent component) {
    StringBuffer buffer = new StringBuffer();
    JSFunction function = new JSFunction("new RichFaces.Menu.Layer");
    function.addParameter(component.getClientId(context)+"_menu");
    function.addParameter(component.getAttributes().get("showDelay"));
       
    if (component instanceof UIDropDownMenu) {
        function.addParameter(component.getAttributes().get("hideDelay"));
        Object selectedClass = component.getAttributes().get("selectedLabelClass");
        if (null != selectedClass && !"".equals(selectedClass)) {
          function.addParameter(selectedClass);
        }
        } else {
          function.addParameter(new Integer(300));
        }
       
    function.appendScript(buffer);
   
    if (component instanceof UIMenuGroup) {
        buffer.append(".");
        function = new JSFunction("asSubMenu");
        function.addParameter(component.getParent().getClientId(context)+"_menu");
        function.addParameter(component.getClientId(context));
         String evt = (String) component.getAttributes().get("event");
        if(evt == null || evt.trim().length() == 0){
          evt = "onmouseover";
        }
        function.addParameter(evt);
        ScriptOptions subMenuOptions = new ScriptOptions(component);
        subMenuOptions.addEventHandler("onopen");
        subMenuOptions.addEventHandler("onclose");
        subMenuOptions.addOption("direction");
        subMenuOptions.addOption("highlightParent", Boolean.TRUE);
        function.addParameter(subMenuOptions);
        function.appendScript(buffer);

    } else {
        buffer.append(".");
        function = new JSFunction("asDropDown");
        function.addParameter(component.getClientId(context));
        function.addParameter(component.getClientId(context) + "_span");
          String evt = (String) component.getAttributes().get("event");
        if(evt == null || evt.trim().length() == 0){
          evt = "onmouseover";
        }
        function.addParameter(evt);
        function.addParameter("onmouseout");
        ScriptOptions menuOptions = new ScriptOptions(component);

        menuOptions.addOption("direction");
        menuOptions.addOption("jointPoint");
        menuOptions.addOption("verticalOffset");


        menuOptions.addOption("horizontalOffset");
        menuOptions.addEventHandler("oncollapse");
        menuOptions.addEventHandler("onexpand");
        menuOptions.addEventHandler("onitemselect");
        menuOptions.addEventHandler("ongroupactivate");
        menuOptions.addOption("disabled");
        function.addParameter(menuOptions);
        function.appendScript(buffer);

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

      } else {
        flagGroup = 1;
      }
    }
    if (itemId != null) {
      JSFunction function = new JSFunction(".addItem");
      function.addParameter(itemId);
      ScriptOptions options = new ScriptOptions(kid);
      options.addEventHandler("onmouseout");
      options.addEventHandler("onmouseover");
      options.addOption("closeOnClick", new Integer(flcloseonclick));
      options.addOption("flagGroup", new Integer(flagGroup));
      options.addOption("selectClass");
      options.addOption("style");
      options.addOption("selectStyle");
      options.addOption("iconClass");
      options.addOption("disabled", Boolean.valueOf(disabled));
      function.addParameter(options);
      return function.toScript();
    }
    return "";
  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.richfaces.renderkit.html.AbstractMenuRenderer#getLayerScript(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
   */
  protected String getLayerScript(FacesContext context, UIComponent component) {
    StringBuffer buffer = new StringBuffer();
    JSFunction function = new JSFunction("new RichFaces.Menu.Layer");
    function.addParameter(component.getClientId(context)+"_menu");
    function.addParameter(component.getAttributes().get("showDelay"));
       
    if (component instanceof UIContextMenu) {
        function.addParameter(component.getAttributes().get("hideDelay"));
        } else {
          function.addParameter(new Integer(300));
        }
       
    function.appendScript(buffer);
   
    if (component instanceof UIMenuGroup) {
        buffer.append(".");
        function = new JSFunction("asSubMenu");
        function.addParameter(component.getParent().getClientId(context)+"_menu");
        function.addParameter(component.getClientId(context));
         String evt = (String) component.getAttributes().get("event");
        if(evt == null || evt.trim().length() == 0){
          evt = "onmouseover";
        }
        function.addParameter(evt);
        ScriptOptions subMenuOptions = new ScriptOptions(component);
        subMenuOptions.addEventHandler("onopen");
        subMenuOptions.addEventHandler("onclose");
        subMenuOptions.addOption("direction");
        subMenuOptions.addOption("dummy", "dummy");
        function.addParameter(subMenuOptions);
        function.appendScript(buffer);

    } else {
        buffer.append(".");
        function = new JSFunction("asContextMenu");
/*        function.addParameter(component.getParent().getClientId(context));
          String evt = (String) component.getAttributes().get("event");
        if(evt == null || evt.trim().length() == 0){
          evt = "oncontextmenu";
        }
        function.addParameter(evt);
        function.addParameter("onmouseout");
*/        ScriptOptions menuOptions = new ScriptOptions(component);

        menuOptions.addOption("direction");
        menuOptions.addOption("jointPoint");
        menuOptions.addOption("verticalOffset");


        menuOptions.addOption("horizontalOffset");
        menuOptions.addEventHandler("oncollapse");
        menuOptions.addEventHandler("onexpand");
        menuOptions.addEventHandler("onitemselect");
        menuOptions.addEventHandler("ongroupactivate");
       
        menuOptions.addOption("dummy", "dummy");
        function.addParameter(menuOptions);
        function.appendScript(buffer);

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

      JSReference eventRef = new JSReference("event");
      String panelId = tgComp.getClientId(context);

  if (UISimpleTogglePanel.CLIENT_SWITCH_TYPE.equals(switchType)) {
            // Client
            JSFunction function = new JSFunction("SimpleTogglePanelManager.toggleOnClient");
            function.addParameter(eventRef);
            function.addParameter(panelId);
            function.appendScript(onClick);
            onClick.append(";");
           
        } else if (UISimpleTogglePanel.AJAX_SWITCH_TYPE.equals(switchType)) {
//      Ajax
                  
          JSFunction function = new JSFunction("SimpleTogglePanelManager.toggleOnAjax");
          function.addParameter(eventRef);
          function.addParameter(panelId);
          function.appendScript(onClick);
          onClick.append(";");
       
          JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(tgComp, context);
          ajaxFunction.addParameter(AjaxRendererUtils.buildEventOptions(context, tgComp));
             ajaxFunction.appendScript(onClick);
            
             if (tgComp instanceof AjaxSupport) {
          AjaxSupport support = (AjaxSupport) tgComp;
          if (support.isDisableDefault()) {
            onClick.append("; return false;");
          }
        }

        } else {
            // Server
          JSFunction function = new JSFunction("SimpleTogglePanelManager.toggleOnServer")
            function.addParameter(eventRef);
            function.addParameter(panelId);
            function.appendScript(onClick);
            onClick.append(";");       
            //.append(tgComp.getSwitch()==null?"'0'":"'" + tgComp.getSwitch() + "'")
            //.append("")
        }
        return onClick.toString();
View Full Code Here

                        requestOpts.put("control", JSReference.THIS);
                }
                parameters.put(dataColumn.getParent().getClientId(context)
                        + ":" + CHANGE_COL_VISIBILITY, dataColumn.getId());

                JSFunction dropFunction = AjaxRendererUtils.buildAjaxFunction(
                        dataColumn, context);
                dropFunction.addParameter(requestOpts);
                actionScript = dropFunction.toScript();
            }// if

            writer.startElement("li", dataColumn);
            writer.writeAttribute(HTML.class_ATTRIBUTE, "dt-menu-list-item"
                    + (columnVisible ? " dt-menu-item-checked" : ""), null);
View Full Code Here

TOP

Related Classes of org.ajax4jsf.javascript.JSFunction

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.