Search in sources :

Example 1 with IValueMap

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

the class ObjectContainer method onComponentTag.

@Override
public void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);
    // get the attributes from the html-source
    IValueMap attributeMap = tag.getAttributes();
    // set the content type
    String contentType = getContentType();
    if (contentType != null && !"".equals(contentType))
        attributeMap.put(ATTRIBUTE_CONTENTTYPE, contentType);
    // set clsid and codebase for IE
    if (getClientProperties().isBrowserInternetExplorer()) {
        String clsid = getClsid();
        String codeBase = getCodebase();
        if (clsid != null && !"".equals(clsid))
            attributeMap.put(ATTRIBUTE_CLASSID, clsid);
        if (codeBase != null && !"".equals(codeBase))
            attributeMap.put(ATTRIBUTE_CODEBASE, codeBase);
    }
    // add all attributes
    for (String name : getAttributeNames()) {
        String value = getValue(name);
        if (value != null)
            attributeMap.put(name, value);
    }
}
Also used : IValueMap(org.apache.wicket.util.value.IValueMap)

Example 2 with IValueMap

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

the class RadioChoice method appendOptionHtml.

/**
 * Generates and appends html for a single choice into the provided buffer
 *
 * @param buffer
 *            Appending string buffer that will have the generated html appended
 * @param choice
 *            Choice object
 * @param index
 *            The index of this option
 * @param selected
 *            The currently selected string value
 */
@SuppressWarnings("unchecked")
@Override
protected void appendOptionHtml(final AppendingStringBuffer buffer, final T choice, int index, final String selected) {
    Object displayValue = getChoiceRenderer().getDisplayValue(choice);
    Class<?> objectClass = (displayValue == null ? null : displayValue.getClass());
    // Get label for choice
    String label = "";
    if (objectClass != null && objectClass != String.class) {
        @SuppressWarnings("rawtypes") final IConverter converter = getConverter(objectClass);
        label = converter.convertToString(displayValue, getLocale());
    } else if (displayValue != null) {
        label = displayValue.toString();
    }
    // location in the page markup!
    if (label != null) {
        // Append option suffix
        buffer.append(getPrefix(index, choice));
        String id = getChoiceRenderer().getIdValue(choice, index);
        final String idAttr = getMarkupId() + "-" + id;
        boolean enabled = isEnabledInHierarchy() && !isDisabled(choice, index, selected);
        // Add label for radio button
        String display = label;
        if (localizeDisplayValues()) {
            display = getLocalizer().getString(label, this, label);
        }
        CharSequence escaped = display;
        if (getEscapeModelStrings()) {
            escaped = Strings.escapeMarkup(display);
        }
        // Allows user to add attributes to the <label..> tag
        IValueMap labelAttrs = getAdditionalAttributesForLabel(index, choice);
        StringBuilder extraLabelAttributes = new StringBuilder();
        if (labelAttrs != null) {
            for (Map.Entry<String, Object> attr : labelAttrs.entrySet()) {
                extraLabelAttributes.append(' ').append(Strings.escapeMarkup(attr.getKey())).append("=\"").append(Strings.escapeMarkup(attr.getValue().toString())).append('"');
            }
        }
        switch(labelPosition) {
            case BEFORE:
                buffer.append("<label for=\"").append(Strings.escapeMarkup(idAttr)).append('"').append(extraLabelAttributes).append('>').append(escaped).append("</label>");
                break;
            case WRAP_BEFORE:
                buffer.append("<label").append(extraLabelAttributes).append('>').append(escaped).append(' ');
                break;
            case WRAP_AFTER:
                buffer.append("<label").append(extraLabelAttributes).append('>');
                break;
        }
        // Add radio tag
        buffer.append("<input name=\"").append(getInputName()).append('"').append(" type=\"radio\"").append((isSelected(choice, index, selected) ? " checked=\"checked\"" : "")).append((enabled ? "" : " disabled=\"disabled\"")).append(" value=\"").append(Strings.escapeMarkup(id)).append("\" id=\"").append(Strings.escapeMarkup(idAttr)).append('"');
        // Allows user to add attributes to the <input..> tag
        {
            IValueMap attrs = getAdditionalAttributes(index, choice);
            if (attrs != null) {
                for (Map.Entry<String, Object> attr : attrs.entrySet()) {
                    buffer.append(' ').append(Strings.escapeMarkup(attr.getKey())).append("=\"").append(Strings.escapeMarkup(attr.getValue().toString())).append('"');
                }
            }
        }
        DebugSettings debugSettings = getApplication().getDebugSettings();
        String componentPathAttributeName = debugSettings.getComponentPathAttributeName();
        if (Strings.isEmpty(componentPathAttributeName) == false) {
            CharSequence path = getPageRelativePath();
            path = Strings.replaceAll(path, "_", "__");
            path = Strings.replaceAll(path, ":", "_");
            buffer.append(' ').append(componentPathAttributeName).append("=\"").append(path).append("_input_").append(index).append('"');
        }
        buffer.append("/>");
        switch(labelPosition) {
            case WRAP_BEFORE:
                buffer.append("</label>");
                break;
            case WRAP_AFTER:
                buffer.append(' ').append(escaped).append("</label>");
                break;
            case AFTER:
                buffer.append("<label for=\"").append(Strings.escapeMarkup(idAttr)).append('"').append(extraLabelAttributes).append('>').append(escaped).append("</label>");
                break;
        }
        // Append option suffix
        buffer.append(getSuffix(index, choice));
    }
}
Also used : IValueMap(org.apache.wicket.util.value.IValueMap) DebugSettings(org.apache.wicket.settings.DebugSettings) IConverter(org.apache.wicket.util.convert.IConverter) Map(java.util.Map) IValueMap(org.apache.wicket.util.value.IValueMap)

Example 3 with IValueMap

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

the class Choices method onComponentTag.

@Override
protected void onComponentTag(final ComponentTag tag) {
    super.onComponentTag(tag);
    IValueMap attrs = tag.getAttributes();
    String onFocus = getPalette().getChoicesOnFocusJS();
    if (onFocus != null) {
        attrs.put("onfocus", onFocus);
    }
    tag.getAttributes().put("ondblclick", getPalette().getAddOnClickJS());
}
Also used : IValueMap(org.apache.wicket.util.value.IValueMap)

Example 4 with IValueMap

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

the class Selection method onComponentTag.

@Override
protected void onComponentTag(final ComponentTag tag) {
    super.onComponentTag(tag);
    IValueMap attrs = tag.getAttributes();
    String onFocus = getPalette().getSelectionOnFocusJS();
    if (onFocus != null) {
        attrs.put("onfocus", onFocus);
    }
    tag.getAttributes().put("ondblclick", getPalette().getRemoveOnClickJS());
}
Also used : IValueMap(org.apache.wicket.util.value.IValueMap)

Example 5 with IValueMap

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

the class CheckBoxMultipleChoice method appendOptionHtml.

/**
 * Generates and appends html for a single choice into the provided buffer
 *
 * @param buffer
 *            Appending string buffer that will have the generated html appended
 * @param choice
 *            Choice object
 * @param index
 *            The index of this option
 * @param selected
 *            The currently selected string value
 */
@SuppressWarnings("unchecked")
@Override
protected void appendOptionHtml(final AppendingStringBuffer buffer, final T choice, int index, final String selected) {
    Object displayValue = getChoiceRenderer().getDisplayValue(choice);
    Class<?> objectClass = displayValue == null ? null : displayValue.getClass();
    // Get label for choice
    String label = "";
    if (objectClass != null && objectClass != String.class) {
        @SuppressWarnings("rawtypes") IConverter converter = getConverter(objectClass);
        label = converter.convertToString(displayValue, getLocale());
    } else if (displayValue != null) {
        label = displayValue.toString();
    }
    // location in the page markup!
    if (label != null) {
        // Append option suffix
        buffer.append(getPrefix(index, choice));
        String id = getChoiceRenderer().getIdValue(choice, index);
        final String idAttr = getCheckBoxMarkupId(id);
        // Add label for checkbox
        String display = label;
        if (localizeDisplayValues()) {
            display = getLocalizer().getString(label, this, label);
        }
        final CharSequence escaped = (getEscapeModelStrings() ? Strings.escapeMarkup(display) : display);
        // Allows user to add attributes to the <label..> tag
        IValueMap labelAttrs = getAdditionalAttributesForLabel(index, choice);
        StringBuilder extraLabelAttributes = new StringBuilder();
        if (labelAttrs != null) {
            for (Map.Entry<String, Object> attr : labelAttrs.entrySet()) {
                extraLabelAttributes.append(' ').append(Strings.escapeMarkup(attr.getKey())).append("=\"").append(Strings.escapeMarkup(attr.getValue().toString())).append('"');
            }
        }
        switch(labelPosition) {
            case BEFORE:
                buffer.append("<label for=\"").append(Strings.escapeMarkup(idAttr)).append('"').append(extraLabelAttributes).append('>').append(escaped).append("</label>");
                break;
            case WRAP_BEFORE:
                buffer.append("<label").append(extraLabelAttributes).append('>').append(escaped).append(' ');
                break;
            case WRAP_AFTER:
                buffer.append("<label").append(extraLabelAttributes).append('>');
                break;
        }
        // Add checkbox element
        buffer.append("<input name=\"");
        buffer.append(getInputName());
        buffer.append('"');
        buffer.append(" type=\"checkbox\"");
        if (isSelected(choice, index, selected)) {
            buffer.append(" checked=\"checked\"");
        }
        if (isDisabled(choice, index, selected) || !isEnabledInHierarchy()) {
            buffer.append(" disabled=\"disabled\"");
        }
        buffer.append(" value=\"");
        buffer.append(Strings.escapeMarkup(id));
        buffer.append("\" id=\"");
        buffer.append(Strings.escapeMarkup(idAttr));
        buffer.append('"');
        // Allows user to add attributes to the <input..> tag
        {
            IValueMap attrs = getAdditionalAttributes(index, choice);
            if (attrs != null) {
                for (Map.Entry<String, Object> attr : attrs.entrySet()) {
                    buffer.append(' ').append(Strings.escapeMarkup(attr.getKey())).append("=\"").append(Strings.escapeMarkup(attr.getValue().toString())).append('"');
                }
            }
        }
        DebugSettings debugSettings = getApplication().getDebugSettings();
        String componentPathAttributeName = debugSettings.getComponentPathAttributeName();
        if (Strings.isEmpty(componentPathAttributeName) == false) {
            CharSequence path = getPageRelativePath();
            path = Strings.replaceAll(path, "_", "__");
            path = Strings.replaceAll(path, ":", "_");
            buffer.append(' ').append(componentPathAttributeName).append("=\"").append(path).append("_input_").append(index).append('"');
        }
        buffer.append("/>");
        switch(labelPosition) {
            case WRAP_BEFORE:
                buffer.append("</label>");
                break;
            case WRAP_AFTER:
                buffer.append(' ').append(escaped).append("</label>");
                break;
            case AFTER:
                buffer.append("<label for=\"").append(Strings.escapeMarkup(idAttr)).append('"').append(extraLabelAttributes).append('>').append(escaped).append("</label>");
                break;
        }
        // Append option suffix
        buffer.append(getSuffix(index, choice));
    }
}
Also used : DebugSettings(org.apache.wicket.settings.DebugSettings) IValueMap(org.apache.wicket.util.value.IValueMap) IConverter(org.apache.wicket.util.convert.IConverter) IValueMap(org.apache.wicket.util.value.IValueMap) Map(java.util.Map)

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