/** @see org.apache.wicket.behavior.AbstractBehavior#onRendered(org.apache.wicket.Component) */ public void onRendered(Component component) { super.onRendered(component); // Append the span and img icon right after the rendering of the // component. Not as pretty as working with a panel etc, but works // for behaviors and is more efficient Response response = component.getResponse(); response.write("\n<span> <img style=\""); response.write(getIconStyle()); response.write("\" id=\""); response.write(getIconId()); response.write("\" src=\""); CharSequence iconUrl = getIconUrl(); // displayCalendar(document.forms[0].theDate,'yyyy/mm/dd',this) response.write(Strings.escapeMarkup(iconUrl != null ? iconUrl.toString() : "")); response.write("\" onclick=\"displayCalendar(document.getElementById('"); response.write(component.getMarkupId()); response.write("'),'"); String datePattern = getDatePattern().replaceAll("mm", "ii").toLowerCase(); datePattern = datePattern.replace('s', '0'); // (mili)seconds are not supported response.write(datePattern); if (datePattern.indexOf("h") == -1) { response.write("',this)\""); } else { response.write("',this,true)\""); } response.write(" /></span>"); }
private void writeMessages(Component component, Response response) { // // Note how bootstrap cannot have separate markup // for error/info messages attached to the same field. // for (FeedbackMessage message : collectMessages(component)) { response.write("<span class=\"help-block\">"); response.write(Strings.escapeMarkup(message.getMessage().toString())); response.write("</span>"); } }
private void writeLabel(FormComponent<?> fc, Response response) { final IModel<String> labelModel = fc.getLabel(); if (labelModel != null) { String markupId = fc.getMarkupId(); response.write("<label class=\"control-label\" for=\"" + markupId + "\">"); response.write(Strings.escapeMarkup(labelModel.getObject())); if (fc.isRequired() && fc.isEnabled()) { response.write(REQUIRED_STAR); } response.write("</label>"); } }
/** * Write a reference to a javascript file to the response object * * @param response The HTTP response * @param url The javascript file URL * @param id Unique identifier of element * @param defer specifies that the execution of a script should be deferred (delayed) until after * the page has been loaded. * @param charset a non null value specifies the charset attribute of the script tag */ public static void writeJavaScriptUrl( final Response response, final CharSequence url, final String id, boolean defer, String charset) { response.write("<script type=\"text/javascript\" "); if (id != null) { response.write("id=\"" + Strings.escapeMarkup(id) + "\" "); } if (defer) { response.write("defer=\"defer\" "); } if (charset != null) { response.write("charset=\"" + Strings.escapeMarkup(charset) + "\" "); } response.write("src=\""); response.write(Strings.escapeMarkup(url)); response.write("\"></script>"); response.write("\n"); }
/** @see org.apache.wicket.behavior.AbstractBehavior#onRendered(org.apache.wicket.Component) */ @Override public void onRendered(Component component) { // do not add default spans for + -; img buttons substitute those if (getSpinUpComponent() == null) { Response response = component.getResponse(); response.write( "</td><td style = \"margin: 0px; padding: 0px; width: 5px;\"> </td><td style = \"margin: 0px; padding: 0px; width: 16px;\">"); //$NON-NLS-1$ response.write( "<table style=\"margin: 0px; padding: 0px; border-collapse: collapse; table-layout: fixed;\"><tbody><tr style=\"margin: 0px; padding: 0px;\">"); //$NON-NLS-1$ response.write("<td style=\"margin: 0px; padding: 0px;\">"); // $NON-NLS-1$ response.write("\n<img style=\"cursor: pointer; border: none;\" id=\""); // $NON-NLS-1$ response.write(field.getMarkupId() + "-SpinnerUp"); // $NON-NLS-1$ response.write("\" src=\""); // $NON-NLS-1$ response.write(Strings.escapeMarkup(getUpIconUrl().toString())); response.write( "\"/></td></tr><tr style=\"margin: 0px; padding: 0px;\"><td style=\"margin: 0px; padding: 0px;\">"); //$NON-NLS-1$ response.write("\n<img style=\"cursor: pointer; border: none;\" id=\""); // $NON-NLS-1$ response.write(field.getMarkupId() + "-SpinnerDown"); // $NON-NLS-1$ response.write("\" src=\""); // $NON-NLS-1$ response.write(Strings.escapeMarkup(getDownIconUrl().toString())); response.write("\"/></td></tr></tbody></table>"); // $NON-NLS-1$ } }
/** * Write the tag to the response * * @param response The response to write to * @param stripWicketAttributes if true, wicket:id are removed from output * @param namespace Wicket's namespace to use */ public final void writeOutput( final Response response, final boolean stripWicketAttributes, final String namespace) { response.write("<"); if (getType() == TagType.CLOSE) { response.write("/"); } if (getNamespace() != null) { response.write(getNamespace()); response.write(":"); } response.write(getName()); String namespacePrefix = null; if (stripWicketAttributes == true) { namespacePrefix = namespace + ":"; } if (getAttributes().size() > 0) { for (String key : getAttributes().keySet()) { if (key == null) { continue; } if ((namespacePrefix == null) || (key.startsWith(namespacePrefix) == false)) { response.write(" "); response.write(key); CharSequence value = getAttribute(key); // attributes without values are possible, e.g.' disabled' if (value != null) { response.write("=\""); value = Strings.escapeMarkup(value); response.write(value); response.write("\""); } } } } if (getType() == TagType.OPEN_CLOSE) { response.write("/"); } response.write(">"); }
@Override public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { Object[] objects = new Object[models.length]; int i = 0; for (IModel model : models) { Object object = model.getObject(); objects[i] = object; i++; } String label = valuesFormatter.format(objects); // label = StringUtils.removeIsoControls(label); // breaks java script if (escapeHtml) { label = Strings.escapeMarkup(label, false, false).toString(); } replaceComponentTagBody(markupStream, openTag, label); }
/** * @see org.apache.wicket.Component#onComponentTagBody(org.apache.wicket.markup.MarkupStream, * org.apache.wicket.markup.ComponentTag) */ @Override protected final void onComponentTagBody( final MarkupStream markupStream, final ComponentTag openTag) { // Iterate through choices final List<? extends T> choices = getChoices(); // Buffer to hold generated body final AppendingStringBuffer buffer = new AppendingStringBuffer(70 * (choices.size() + 1)); // Value of this choice final String selected = getValue(); // Loop through choices for (int index = 0; index < choices.size(); index++) { // Get next choice final T choice = choices.get(index); Object displayValue = getChoiceRenderer().getDisplayValue(choice); Class<?> objectClass = displayValue == null ? null : displayValue.getClass(); // Get label for choice String label = ""; if (objectClass != null && objectClass != String.class) { IConverter converter = getConverter(objectClass); label = converter.convertToString(displayValue, getLocale()); } else if (displayValue != null) { label = displayValue.toString(); } // If there is a display value for the choice, then we know that the // choice is automatic in some way. If label is /null/ then we know // that the choice is a manually created checkbox tag at some random // location in the page markup! if (label != null) { // Append option suffix buffer.append(getPrefix()); String id = getChoiceRenderer().getIdValue(choice, index); final String idAttr = getMarkupId() + "-" + getInputName() + "_" + id; // Add checkbox element buffer .append("<input name=\"") .append(getInputName()) .append("\"") .append(" type=\"checkbox\""); if (!Strings.isEmpty(getCheckBoxCssClass())) { buffer.append(" class=\"").append(getCheckBoxCssClass()).append("\""); } buffer .append((isSelected(choice, index, selected) ? " checked=\"checked\"" : "")) .append( (isEnabledInHierarchy() && !isDisabled(choice, index, selected) ? "" : " disabled=\"disabled\"")) .append(" value=\"") .append(id) .append("\" id=\"") .append(idAttr) .append("\"/>"); // Add label for checkbox String display = label; if (localizeDisplayValues()) { display = getLocalizer().getString(label, this, label); } CharSequence escaped = display; if (getEscapeModelStrings()) { escaped = Strings.escapeMarkup(display); } buffer.append("<label for=\"").append(idAttr).append("\""); if (!Strings.isEmpty(getCheckBoxLabelCssClass())) { buffer.append(" class=\"").append(getCheckBoxLabelCssClass()).append("\""); } buffer.append(">").append(escaped).append("</label>"); // Append option suffix buffer.append(getSuffix()); } } // Replace body replaceComponentTagBody(markupStream, openTag, buffer); }