Search in sources :

Example 6 with IValueMap

use of org.apache.wicket.util.value.IValueMap in project wicket by apache.

the class AttributeModifier method replaceAttributeValue.

/**
 * Checks the given component tag for an instance of the attribute to modify and if all criteria
 * are met then replace the value of this attribute with the value of the contained model
 * object.
 *
 * @param component
 *            The component
 * @param tag
 *            The tag to replace the attribute value for
 */
public final void replaceAttributeValue(final Component component, final ComponentTag tag) {
    if (isEnabled(component)) {
        final IValueMap attributes = tag.getAttributes();
        final Object replacementValue = getReplacementOrNull(component);
        if (VALUELESS_ATTRIBUTE_ADD == replacementValue) {
            attributes.put(attribute, null);
        } else if (VALUELESS_ATTRIBUTE_REMOVE == replacementValue) {
            attributes.remove(attribute);
        } else {
            final String value = toStringOrNull(attributes.get(attribute));
            final Serializable newValue = newValue(value, toStringOrNull(replacementValue));
            if (newValue == VALUELESS_ATTRIBUTE_REMOVE) {
                attributes.remove(attribute);
            } else if (newValue != null) {
                attributes.put(attribute, newValue);
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) IValueMap(org.apache.wicket.util.value.IValueMap)

Example 7 with IValueMap

use of org.apache.wicket.util.value.IValueMap in project gitblit by gitblit.

the class ShockWaveComponent method onComponentTag.

@Override
public void onComponentTag(ComponentTag tag) {
    // get options from the markup
    IValueMap valueMap = tag.getAttributes();
    // Iterate over valid options
    for (String s : optionNames) {
        if (valueMap.containsKey(s)) {
            // if option isn't set programmatically, set value from markup
            if (!attributes.containsKey(s) && !parameters.containsKey(s))
                setValue(s, valueMap.getString(s));
            // remove attribute - they are added in super.onComponentTag()
            // to
            // the right place as attribute or param
            valueMap.remove(s);
        }
    }
    super.onComponentTag(tag);
}
Also used : IValueMap(org.apache.wicket.util.value.IValueMap)

Example 8 with IValueMap

use of org.apache.wicket.util.value.IValueMap in project wicket by apache.

the class NumberTextField method onComponentTag.

@Override
protected void onComponentTag(final ComponentTag tag) {
    super.onComponentTag(tag);
    IValueMap attributes = tag.getAttributes();
    final N min = minimum.getObject();
    if (min != null) {
        attributes.put("min", Objects.stringValue(min));
    } else {
        attributes.remove("min");
    }
    final N max = maximum.getObject();
    if (max != null) {
        attributes.put("max", Objects.stringValue(max));
    } else {
        attributes.remove("max");
    }
    final N _step = step.getObject();
    if (_step != null) {
        if (_step.doubleValue() == ANY) {
            attributes.put("step", "any");
        } else {
            attributes.put("step", Objects.stringValue(_step));
        }
    } else {
        attributes.remove("step");
    }
}
Also used : IValueMap(org.apache.wicket.util.value.IValueMap)

Example 9 with IValueMap

use of org.apache.wicket.util.value.IValueMap in project wicket by apache.

the class WicketMessageResolver method resolve.

@Override
public Component resolve(final MarkupContainer container, final MarkupStream markupStream, final ComponentTag tag) {
    if (tag instanceof WicketTag) {
        WicketTag wtag = (WicketTag) tag;
        if (wtag.isMessageTag()) {
            IValueMap attributes = wtag.getAttributes();
            String messageKey = attributes.getString(KEY_ATTRIBUTE);
            if (Strings.isEmpty(messageKey)) {
                throw new MarkupException("Wrong format of <wicket:message key='xxx'>: attribute 'key' is missing");
            }
            boolean escape = attributes.getBoolean(ESCAPE_ATTRIBUTE);
            final String id = wtag.getId();
            MessageContainer label = new MessageContainer(id, messageKey, escape);
            label.setRenderBodyOnly(container.getApplication().getMarkupSettings().getStripWicketTags());
            return label;
        }
    }
    // We were not able to handle the tag
    return null;
}
Also used : WicketTag(org.apache.wicket.markup.WicketTag) IValueMap(org.apache.wicket.util.value.IValueMap) MarkupException(org.apache.wicket.markup.MarkupException)

Example 10 with IValueMap

use of org.apache.wicket.util.value.IValueMap in project wicket by apache.

the class TagTester method getAttribute.

/**
 * Gets the value for a given attribute. Please note that this is non case-sensitive, because
 * attributes in HTML may be non case-sensitive.
 *
 * @param attribute
 *            an attribute to look for in the tag
 * @return the value of the attribute or <code>null</code> if it isn't found.
 */
public String getAttribute(String attribute) {
    String value = null;
    IValueMap attributeMap = openTag.getAttributes();
    if (attributeMap != null) {
        for (String attr : attributeMap.keySet()) {
            if (attr.equalsIgnoreCase(attribute)) {
                value = attributeMap.getString(attr);
            }
        }
    }
    return value;
}
Also used : IValueMap(org.apache.wicket.util.value.IValueMap)

Aggregations

IValueMap (org.apache.wicket.util.value.IValueMap)14 Map (java.util.Map)3 DebugSettings (org.apache.wicket.settings.DebugSettings)2 IConverter (org.apache.wicket.util.convert.IConverter)2 Serializable (java.io.Serializable)1 MarkupException (org.apache.wicket.markup.MarkupException)1 WicketTag (org.apache.wicket.markup.WicketTag)1 AppendingStringBuffer (org.apache.wicket.util.string.AppendingStringBuffer)1