Example usage for org.apache.wicket.util.string Strings isEmpty

List of usage examples for org.apache.wicket.util.string Strings isEmpty

Introduction

In this page you can find the example usage for org.apache.wicket.util.string Strings isEmpty.

Prototype

public static boolean isEmpty(final CharSequence string) 

Source Link

Document

Checks whether the string is considered empty.

Usage

From source file:com.googlecode.wicketwebbeans.fields.AbstractField.java

License:Apache License

protected void setFieldParameters(FormComponent field) {
    Integer maxLength = getMaxLength();
    if (maxLength != null) {
        field.add(new SimpleAttributeModifier("maxlength", maxLength.toString()));
    }/*from  w w  w  .j a  v  a  2s.  c o m*/

    String defaultValue = getDefaultValue();
    if (defaultValue != null && Strings.isEmpty(getDefaultModelObjectAsString())) {
        field.setModelValue(defaultValue);
    }
}

From source file:com.googlecode.wicketwebbeans.fields.DropDownChoiceField.java

License:Apache License

/**
 * Construct a new DropDownChoiceField.//from   w w w .j  ava 2  s  .  c om
 *
 * @param id the Wicket id for the editor.
 * @param model the model.
 * @param metaData the meta data for the property.
 * @param viewOnly true if the component should be view-only.
 * @param valueModel the Bean List of drop down choices 
 * @param choiceRenderer displays the bean value
 *  produce the value displayed to the user.
 */
public DropDownChoiceField(String id, IModel<Serializable> model, ElementMetaData metaData, boolean viewOnly,
        IModel<? extends List<? extends Serializable>> valueModel, final IChoiceRenderer choiceRenderer) {
    super(id, model, metaData, viewOnly);

    Fragment fragment;
    if (viewOnly) {
        fragment = new Fragment("frag", "viewer");
        fragment.add(new LabelWithMinSize("component", model) {
            protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
                String value = choiceRenderer.getDisplayValue(getDefaultModelObject()).toString();
                if (Strings.isEmpty(value)) {
                    value = "&nbsp;";
                    setEscapeModelStrings(false);
                }
                replaceComponentTagBody(markupStream, openTag, value);
            }
        });
    } else {
        fragment = new Fragment("frag", "editor");
        choice = new DropDownChoice("component", model, valueModel, choiceRenderer);
        // Always allow the null choice.
        choice.setNullValid(true);
        fragment.add(choice);
    }
    add(fragment);
}

From source file:com.googlecode.wicketwebbeans.fields.EnumField.java

License:Apache License

/**
 * Construct a new EnumField./*w  w w. jav a2s .co  m*/
 *
 * @param id the Wicket id for the editor.
 * @param model the model.
 * @param metaData the meta data for the property.
 * @param viewOnly true if the component should be view-only.
 * @param valueModel an IModel that returns a List of values to be selected from. The element's toString() is used to 
 *  produce the value displayed to the user.
 * @param choiceRenderer a renderer that produces the value displayed to the user. May be null to use the default rendering.
 */
public EnumField(String id, IModel model, ElementMetaData metaData, boolean viewOnly, IModel valueModel,
        final IChoiceRenderer choiceRenderer) {
    super(id, model, metaData, viewOnly);

    this.choiceRenderer = choiceRenderer;
    Fragment fragment;
    if (viewOnly) {
        fragment = new Fragment("frag", "viewer");
        fragment.add(new LabelWithMinSize("component", model) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
                if (choiceRenderer == null) {
                    super.onComponentTagBody(markupStream, openTag);
                } else {
                    String value = choiceRenderer.getDisplayValue(getDefaultModelObject()).toString();
                    if (Strings.isEmpty(value)) {
                        value = "&nbsp;";
                        setEscapeModelStrings(false);
                    }
                    replaceComponentTagBody(markupStream, openTag, value);
                }
            }
        });
    } else {
        fragment = new Fragment("frag", "editor");
        choice = new DropDownChoice("component", model, valueModel, choiceRenderer);
        // Always allow the null choice.
        choice.setNullValid(true);
        fragment.add(choice);

        initDefault();
    }

    add(fragment);
}

From source file:com.googlecode.wicketwebbeans.fields.LabelWithMinSize.java

License:Apache License

/**
 * {@inheritDoc}/*from ww w .  ja  v a2  s .  co  m*/
 * @param markupStream
 * @param openTag 
 * @see org.apache.wicket.markup.html.basic.Label#onComponentTagBody(wicket.markup.MarkupStream, org.apache.wicket.markup.ComponentTag)
 */
@Override
protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
    String value = getDefaultModelObjectAsString();
    if (Strings.isEmpty(value)) {
        value = "&nbsp;";
        setEscapeModelStrings(false);
    }

    replaceComponentTagBody(markupStream, openTag, value);
}

From source file:com.googlecode.wicketwebbeans.model.BeanMetaData.java

License:Apache License

/**
 * Applies any metadata-based CSS classes for the given bean or property to the component.
 * @param bean//from  w w w. j  a  v a2  s. c  o  m
 * @param metaData
 * @param applyToComponent
 */
public void applyCss(Object bean, MetaData metaData, Component applyToComponent) {
    String css = metaData.getParameter(PARAM_CSS);

    if (!Strings.isEmpty(css)) {
        applyToComponent.add(new AttributeAppender("class", new Model<String>(css), " "));
    }

    String dynamicCssMethod = metaData.getParameter(PARAM_DYNAMIC_CSS);
    if (!Strings.isEmpty(dynamicCssMethod)) {
        Method method = null;
        String cssReturn = null;
        try {
            method = component.getClass().getMethod(dynamicCssMethod,
                    new Class[] { beanClass, metaData.getClass() });
        } catch (NoSuchMethodException ex) {
            throw new RuntimeException("dynamicCss method " + dynamicCssMethod + "(" + beanClass.getName()
                    + ", " + metaData.getClass().getName() + ") is not defined in " + component.getClass());
        } catch (SecurityException ex) {
            throw new RuntimeException("securty exception accessing dynamicCss method " + dynamicCssMethod + "("
                    + beanClass.getName() + ", " + metaData.getClass().getName() + ") in "
                    + component.getClass(), ex);
        }
        if (bean instanceof IModel) {
            bean = ((IModel) bean).getObject();
        }
        try {
            cssReturn = (String) method.invoke(component, new Object[] { bean, metaData });
        } catch (IllegalAccessException ex) {
            throw new RuntimeException("access to dynamicCss method " + dynamicCssMethod + "("
                    + beanClass.getName() + ", " + metaData.getClass().getName() + ") in "
                    + component.getClass() + " is not allowed");
        } catch (IllegalArgumentException ex) {
            throw new RuntimeException(
                    "illegal arguments for dynamicCss method " + dynamicCssMethod + "(" + beanClass.getName()
                            + ", " + metaData.getClass().getName() + ") in " + component.getClass());
        } catch (InvocationTargetException ex) {
            throw new RuntimeException("invocation to dynamicCss method " + dynamicCssMethod + "("
                    + beanClass.getName() + ", " + metaData.getClass().getName() + ") in "
                    + component.getClass() + " has thrown an exception", ex);
        }
        if (!Strings.isEmpty(cssReturn)) {
            applyToComponent.add(new AttributeAppender("class", new Model<String>(cssReturn), " "));
        }
    }
}

From source file:com.googlecode.wicketwebbeans.model.BeanPropertyModel.java

License:Apache License

/**
 * {@inheritDoc}//  w  ww .j  a va 2s  . c om
 * Only sets the object if it is different from what getObject() returns. 
 * 
 * @param object 
 * @see org.apache.wicket.model.AbstractPropertyModel#onSetObject(wicket.Component, java.lang.Object)
 */
@Override
public void setObject(T object) {
    attach();
    Object newValue = object;
    // This, unfortunately, comes in as a String in most cases, so convert it.
    if (newValue instanceof String) {
        final String string = (String) newValue;
        if (!Strings.isEmpty(string)) {
            // and there is a non-null property type for the component
            if (getObjectClass() != null) {
                // convert the String to the right type
                IConverter converter = component.getConverter(getObjectClass());
                if (converter != null) {
                    newValue = converter.convertToObject(string, null);
                }
            }
        }
    }

    // Below in parens is an equality expression that is inverted to say "not (equal)".
    if (!(getObjectCalled // If lastValueGot is valid.
            && lastValueGot == newValue // If they're the same object, or both null
            && (lastValueGot == null || lastValueGot.equals(newValue)))) {
        super.setObject(object);
    }

    getObjectCalled = false;
}

From source file:com.googlecode.wicketwebbeans.model.ErrorHighlightingBehavior.java

License:Apache License

@Override
protected String newValue(String currentValue, String replacementValue) {
    if (Strings.isEmpty(replacementValue)) {
        if (currentValue == null) {
            return "";
        }/*  w  ww  . jav  a  2  s  .  c  o m*/

        // Remove just our class, leaving other classes.
        return currentValue.replace(BEAN_FORM_ERROR_CLASS, "").trim();
    }

    if (currentValue == null) {
        return replacementValue;
    }

    if (currentValue.contains(replacementValue + ' ')) {
        return currentValue;
    }

    return replacementValue + ' ' + currentValue;
}

From source file:com.googlecode.wicketwebbeans.model.MetaData.java

License:Apache License

/**
 * Sets a parameter if the value is not empty or null.
 *
 * @param key the parameter key. If empty or null, the parameter is not set.
 * @param value the parameter value. If empty or null, the parameter is not set.
 *///from w  w w . j av a 2  s  . c  o m
public void setParameterIfNotEmpty(String key, String value) {
    if (!Strings.isEmpty(key) && !Strings.isEmpty(value)) {
        setParameter(key, value);
    }
}

From source file:com.googlecode.wicketwebbeans.model.MetaData.java

License:Apache License

/**
 * Sets a parameter if the values array is not empty or null.
 *
 * @param key the parameter key. If empty or null, the parameter is not set.
 * @param values the parameter values. If empty or null, the parameter is not set.
 *//*from  ww w.j a  va2 s. com*/
public void setParameterIfNotEmpty(String key, String[] values) {
    if (!Strings.isEmpty(key) && values != null && values.length > 0) {
        setParameterValues(key, values);
    }
}

From source file:com.mylab.wicket.jpa.ui.pages.select2.Select2Choice.java

License:Apache License

@Override
protected final T convertValue(String[] value) throws ConversionException {
    if (value != null && value.length > 0 && !Strings.isEmpty(value[0])) {
        Iterator<T> it = convertIdsToChoices(Collections.singletonList(value[0])).iterator();
        return it.hasNext() ? it.next() : null;
    } else {/* w ww. ja  va  2s. c om*/
        return null;
    }
}