Class JsUtil

java.lang.Object
com.webfirmframework.wffweb.js.JsUtil

public final class JsUtil extends Object
Utility methods to generate JavaScript code.
Since:
2.1.1
  • Method Details

    • getJsObjectForFieldsValue

      public static String getJsObjectForFieldsValue(Map<String,Object> jsKeyAndElementId)
      Parameters:
      jsKeyAndElementId - The map containing key values. The key in the map will be used as the key in the generated js object. The value in the map should be the id of the field.
      Returns:
      the JavaScript object for the fields value. Sample : {username:document.getElementById('uId').value}
      Since:
      2.1.1
    • getJsObjectForFieldsValue

      public static String getJsObjectForFieldsValue(Map<String,Object> jsKeyAndElementId, String alternativeFunction)
      Parameters:
      jsKeyAndElementId - The map containing key values. The key in the map will be used as the key in the generated js object. The value in the map should be the id of the field.
      alternativeFunction - alternative function name for document.getElementById
      Returns:
      the JavaScript object for the fields value. Sample : {username:gebi('uId').value} if the alternativeFunction is gebi
      Since:
      3.0.1
    • getJsObjectForFieldsValue

      public static String getJsObjectForFieldsValue(Set<Object> ids)
      Parameters:
      ids - The set containing element ids. The id will be used as the key in the generated js object. The value in the set should be the id of the field. The id in the set should be a valid JavaScript object key.
      Returns:
      the JavaScript object for the fields value. Sample : {uId:document.getElementById('uId').value}
      Since:
      2.1.1
    • getJsObjectForFieldsValue

      public static String getJsObjectForFieldsValue(Set<Object> ids, String alternativeFunction)
      Parameters:
      ids - The set containing element ids. The id will be used as the key in the generated js object. The value in the set should be the id of the field. The id in the set should be a valid JavaScript object key.
      alternativeFunction - alternative function name for document.getElementById
      Returns:
      the JavaScript object for the fields value. Sample : {uId:gebi('uId').value} if alternativeFunction is gebi
      Since:
      3.0.1
    • getJsObjectForFieldsValue

      public static String getJsObjectForFieldsValue(String... ids)
      Parameters:
      ids - The string array containing element ids. The id will be used as the key in the generated js object. The value in the array should be the id of the field. The id in the array should be a valid JavaScript object key.
      Returns:
      the JavaScript object for the fields value. Sample : {uId:document.getElementById('uId'.value)}
      Since:
      2.1.3
    • getJsObjectForFieldsValueWithAltFun

      public static String getJsObjectForFieldsValueWithAltFun(String alternativeFunction, String... ids)
      Parameters:
      ids - The string array containing element ids. The id will be used as the key in the generated js object. The value in the array should be the id of the field. The id in the array should be a valid JavaScript object key.
      alternativeFunction - alternative function name for document.getElementById
      Returns:
      the JavaScript object for the fields value. Sample : {uId:document.getElementById('uId'.value)}
      Since:
      3.0.1
    • getJsObjectForFieldsValue

      public static String getJsObjectForFieldsValue(Set<Object> inputIds, Set<Object> checkboxIds)
      Parameters:
      inputIds - input field ids such as input type text etc..
      checkboxIds - checkbox field ids such as input type checkbox
      Returns:
      the JavaScript object for the fields value. Sample : {usernameInputId:document.getElementById('usernameInputId').value,dateExpiredCheckboxId:document.getElementById('dateExpiredCheckboxId').checked}
      Since:
      3.0.1
    • getJsObjectForFieldsValue

      public static String getJsObjectForFieldsValue(Set<Object> inputIds, Set<Object> checkboxIds, String alternativeFunction)
      Parameters:
      inputIds - input field ids such as input type text etc..
      checkboxIds - checkbox field ids such as input type checkbox
      alternativeFunction - alternative function name for document.getElementById
      Returns:
      the JavaScript object for the fields value. Sample : {usernameInputId:document.getElementById('usernameInputId').value,dateExpiredCheckboxId:document.getElementById('dateExpiredCheckboxId').checked}
      Since:
      3.0.1
    • toDynamicJs

      public static String toDynamicJs(String s)
      This method is mainly for internal use.
      Parameters:
      s -
      Returns:
      the returned string will be striped and all lines will be replace by \n .
      Since:
      3.0.15
    • toDynamicJsString

      public static String toDynamicJsString(String s)
      It replaces all new lines by \n so that it can be used as a dynamic JavaScript string in event attributes js function body. It is unicode aware.
      Parameters:
      s -
      Returns:
      the string having all lines replaced by \n .
      Since:
      3.0.17