Example usage for org.apache.wicket.markup.html.form FormComponent getRawInput

List of usage examples for org.apache.wicket.markup.html.form FormComponent getRawInput

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form FormComponent getRawInput.

Prototype

public final String getRawInput() 

Source Link

Document

Use hasRawInput() to check if this component has raw input because null can mean 2 things: It doesn't have rawinput or the rawinput is really null.

Usage

From source file:com.chitek.wicket.listeditor.UniqueListItemValidator.java

License:Apache License

/**
 * Validator for items in {@link ListEditor}. Validates the input to be unique among all
 * entrys in the list. /*from ww  w . j ava 2 s .  c o  m*/
 */
@SuppressWarnings("rawtypes")
@Override
public void validate(IValidatable<T> validatable) {

    ListEditor<?> editor = parent.findParent(ListEditor.class);
    String id = parent.getId();

    int count = 0;
    List<FormComponent> fields = editor.getComponentsById(id, FormComponent.class);

    String parentValue = getValue(validatable);

    if (filter != null && caseSensitive && !filter.contains(parentValue))
        return;
    if (filter != null && !caseSensitive && !filter.contains(parentValue.toLowerCase()))
        return;
    if (filter != null && !caseSensitive && !filter.contains(parentValue.toUpperCase()))
        return;

    for (FormComponent field : fields) {
        String value = field.getRawInput() != null ? field.getRawInput().toString() : null;

        if (value != null
                && (caseSensitive ? value.equals(parentValue) : value.equalsIgnoreCase(parentValue))) {
            count++;
        }
    }

    if (count > 1) {
        ValidationError error = new ValidationError();
        error.addKey(messageKey);
        validatable.error(error);
    }
}