Example usage for com.google.gwt.dom.client NodeCollection getLength

List of usage examples for com.google.gwt.dom.client NodeCollection getLength

Introduction

In this page you can find the example usage for com.google.gwt.dom.client NodeCollection getLength.

Prototype

public final native int getLength() ;

Source Link

Document

This attribute specifies the length or size of the list.

Usage

From source file:io.reinert.requestor.form.FormDataSerializerUrlEncoded.java

License:Apache License

@Override
public Payload serialize(FormData formData) {
    StringBuilder serialized = new StringBuilder();

    final FormElement formElement = formData.getFormElement();
    if (formElement != null) {
        final NodeCollection<Element> elements = formElement.getElements();
        for (int i = 0; i < elements.getLength(); i++) {
            Element field = elements.getItem(i);

            try {
                if (!field.hasAttribute("name"))
                    continue;
            } catch (JavaScriptException e) {
                continue; // variable is not an element
            }/*from w w  w . ja v a 2 s  .c o  m*/

            String type = field.getNodeName().equalsIgnoreCase("input")
                    ? field.getAttribute("type").toLowerCase()
                    : "text";

            if (type.equals("file")) {
                logger.log(Level.WARNING,
                        "An attempt to serialize a non-string value from a FormData has failed."
                                + " Files and Blobs are not supported by FormDataSerializerUrlEncoded."
                                + " Maybe you want to switch the selected FormDataSerializer via deferred binding.");
                continue;
            }

            if ((type.equals("radio") || type.equals("checkbox")) && !isChecked(field))
                continue;

            final String name = encode(getName(field));
            final String value = encode(getValue(field));
            serialized.append(name).append('=').append(value).append('&'); // append 'name=value&'
        }
        serialized.setLength(serialized.length() - 1); // remove last '&' character
        return new Payload(serialized.toString());
    }

    for (FormData.Param param : formData) {
        final Object value = param.getValue();
        if (value instanceof String) {
            // append 'name=value&'
            serialized.append(encode(param.getName())).append('=').append(encode((String) value)).append('&');
        } else {
            logger.log(Level.WARNING,
                    "An attempt to serialize a non-string value from a FormData has failed."
                            + " Files and Blobs are not supported by FormDataSerializerUrlEncoded"
                            + " You may want to switch the selected FormDataSerializer via deferred binding.");
        }
    }
    serialized.setLength(serialized.length() - 1); // remove last '&' character
    return new Payload(serialized.toString());
}

From source file:org.datacleaner.monitor.shared.widgets.FormWizardClientController.java

License:Open Source License

@Override
public void requestNextPage(final AsyncCallback<WizardPage> callback) {
    final Map<String, List<String>> formParameters = new HashMap<String, List<String>>();

    final FormElement formElement = FormElement.as(_form);

    final NodeCollection<com.google.gwt.dom.client.Element> inputElements = formElement.getElements();
    for (int i = 0; i < inputElements.getLength(); i++) {
        final Element element = inputElements.getItem(i);

        final String name;
        final String value;
        final boolean included;

        final String tagName = element.getTagName();
        if (tagName.equalsIgnoreCase("input")) {
            InputElement inputElement = InputElement.as(element);
            name = inputElement.getName();
            value = inputElement.getValue();

            String type = inputElement.getType();
            if ("checkbox".equals(type) || "radio".equals(type)) {
                included = inputElement.isChecked();
            } else {
                included = true;/*from   w ww .j  av a 2  s  . c o  m*/
            }
        } else {
            // useful for eg. <textarea> and <select> element types
            name = element.getPropertyString("name");
            value = element.getPropertyString("value");
            included = true;
        }

        if (included) {
            List<String> valueList = formParameters.get(name);
            if (valueList == null) {
                valueList = new ArrayList<String>();
                formParameters.put(name, valueList);
            }
            valueList.add(value);
        }
    }

    _service.nextPage(_tenant, _wizardPage.getSessionIdentifier(), formParameters, callback);
}

From source file:rocket.dom.client.Dom.java

License:Apache License

/**
 * Populates the given map with the values of the elements belonging to the
 * given form. The element name becomes the key and teh value the entry
 * value./* www .  jav a 2  s . com*/
 * 
 * FormElements without a name are skipped.
 * 
 * @param map
 *            The destination map
 * @param form
 *            The form containing the elements.
 */
public static void populateMapFromForm(final Map<String, String> map, final FormElement form) {
    Checker.notNull("parameter:map", map);
    Checker.notNull("parameter:form", form);

    final NodeCollection<Element> formElements = form.getElements();
    final int count = formElements.getLength();
    for (int i = 0; i < count; i++) {
        final Element element = formElements.getItem(i);
        final String name = element.getAttribute(DomConstants.NAME);
        if (null == name) {
            continue;
        }

        final String value = Dom.getFormSubmitValue(element);
        map.put(name, value);
    }
}

From source file:rocket.dom.client.Dom.java

License:Apache License

/**
 * Encodes all the elements belonging to form into a safe url encoded
 * String./* w  w  w  . ja  va2 s. c  om*/
 * 
 * @param form
 * @return
 */
public static String urlEncodeForm(final FormElement form) {
    Checker.notNull("parameter:form", form);

    final StringBuffer urlEncoded = new StringBuffer();
    boolean addSeparator = false;

    final NodeCollection<Element> formElements = form.getElements();
    final int count = formElements.getLength();
    for (int i = 0; i < count; i++) {
        final Element element = formElements.getItem(i);
        final String name = element.getAttribute(DomConstants.NAME);
        if (null == name) {
            continue;
        }

        if (addSeparator) {
            urlEncoded.append('&');
        }

        final String value = URL.encodeComponent(Dom.getFormSubmitValue(element));
        urlEncoded.append(name);
        urlEncoded.append('=');
        urlEncoded.append(value);

        addSeparator = true;
    }

    return urlEncoded.toString();
}