com.webfirmframework.wffweb.js.JsUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wffweb Show documentation
Show all versions of wffweb Show documentation
A java framework to develop web applications
/*
* Copyright 2014-2017 Web Firm Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.webfirmframework.wffweb.js;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* Utility methods to generate JavaScript code.
*
* @author WFF
* @since 2.1.1
*/
public class JsUtil {
private JsUtil() {
}
/**
* @param 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.
* @return the JavaScript object for the fields value. Sample :
* {username:document.getElementById("uId")}
* @since 2.1.1
* @author WFF
*/
public static String getJsObjectForFieldsValue(
final Map jsKeyAndElementId) {
final StringBuilder builder = new StringBuilder(38);
builder.append('{');
for (final Entry entry : jsKeyAndElementId.entrySet()) {
builder.append(entry.getKey()).append(":document.getElementById(\"")
.append(entry.getValue().toString()).append("\").value,");
}
builder.replace(builder.length() - 1, builder.length(), "}");
return builder.toString();
}
/**
* @param 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.
* @return the JavaScript object for the fields value. Sample :
* {uId:document.getElementById("uId")}
* @since 2.1.1
* @author WFF
*/
public static String getJsObjectForFieldsValue(final Set
© 2015 - 2025 Weber Informatics LLC | Privacy Policy