use of org.apache.wicket.settings.DebugSettings 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));
}
}
use of org.apache.wicket.settings.DebugSettings 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));
}
}
use of org.apache.wicket.settings.DebugSettings in project wicket by apache.
the class MarkupContainer method addedComponent.
/**
* @param child
* Component being added
*/
private void addedComponent(final Component child) {
// Check for degenerate case
Args.notNull(child, "child");
MarkupContainer parent = child.getParent();
if (parent != null && parent != this) {
parent.remove(child);
}
// Set child's parent
child.setParent(this);
final DebugSettings debugSettings = Application.get().getDebugSettings();
if (debugSettings.isLinePreciseReportingOnAddComponentEnabled() && debugSettings.getComponentUseCheck()) {
child.setMetaData(ADDED_AT_KEY, ComponentStrings.toString(child, new MarkupException("added")));
}
Page page = findPage();
if (page != null) {
// tell the page a component has been added first, to allow it to initialize
page.componentAdded(child);
// initialize the component
if (page.isInitialized()) {
child.internalInitialize();
}
}
// beforeRender on this component's children. So we need to initialize the newly added one
if (isPreparedForRender()) {
child.beforeRender();
}
}
use of org.apache.wicket.settings.DebugSettings in project wicket by apache.
the class CoreLibrariesContributor method contributeAjax.
/**
* Contributes the Ajax backing library plus wicket-event.js and wicket-ajax.js implementations.
* Additionally if Ajax debug is enabled then wicket-ajax-debug.js implementation is also added.
*
* @param application
* the application instance
* @param response
* the current header response
*/
public static void contributeAjax(final Application application, final IHeaderResponse response) {
JavaScriptLibrarySettings jsLibrarySettings = application.getJavaScriptLibrarySettings();
final DebugSettings debugSettings = application.getDebugSettings();
if (debugSettings.isAjaxDebugModeEnabled()) {
response.render(JavaScriptHeaderItem.forReference(jsLibrarySettings.getWicketAjaxDebugReference()));
response.render(JavaScriptHeaderItem.forScript("Wicket.Ajax.DebugWindow.enabled=true;", "wicket-ajax-debug-enable"));
} else {
ResourceReference wicketAjaxReference = jsLibrarySettings.getWicketAjaxReference();
response.render(JavaScriptHeaderItem.forReference(wicketAjaxReference));
}
}
use of org.apache.wicket.settings.DebugSettings in project wicket by apache.
the class Component method onComponentTag.
/**
* Processes the component tag.
*
* Overrides of this method most likely should call the super implementation.
*
* @param tag
* Tag to modify
*/
protected void onComponentTag(final ComponentTag tag) {
// component <-> markup relation)
if (getFlag(FLAG_OUTPUT_MARKUP_ID)) {
tag.putInternal(MARKUP_ID_ATTR_NAME, getMarkupId());
}
DebugSettings debugSettings = getApplication().getDebugSettings();
String componentPathAttributeName = debugSettings.getComponentPathAttributeName();
if (Strings.isEmpty(componentPathAttributeName) == false) {
String path = getPageRelativePath();
path = path.replace("_", "__");
path = path.replace(':', '_');
tag.put(componentPathAttributeName, path);
}
// The markup sourcing strategy may also want to work on the tag
getMarkupSourcingStrategy().onComponentTag(this, tag);
}
Aggregations