@Override protected void writeHeader(Response response, String encoding) { response.write("<?xml version=\"1.0\" encoding=\""); response.write(encoding); response.write("\"?>"); response.write(START_ROOT_ELEMENT); }
@Override public void afterRender(Component component) { Response response = component.getResponse(); writeMessages(component, response); response.write(" </div>"); response.write(" </div>"); }
/* * (non-Javadoc) * * @see org.apache.wicket.behavior.Behavior#onComponentTag(org.apache.wicket.Component, * org.apache.wicket.markup.ComponentTag) */ @Override public void onComponentTag(Component component, ComponentTag tag) { super.onComponentTag(component, tag); if (!Form.class.isAssignableFrom(component.getClass())) { throw new WicketRuntimeException("This behavior is only applicable on a Form component"); } Form<?> form = (Form<?>) component; // Retrieve and set form name String formName = verifyFormName(form, tag); tag.put("onsubmit", "return yav.performCheck('" + formName + "', rules);"); // Open the Yav script (inlined JavaScript) AppendingStringBuffer buffer = new AppendingStringBuffer("<script>\n"); buffer.append("var rules=new Array();\n"); // Visit all form components and check for validators (and write the // appropriate Yav rules in the current inlined JavaScript) form.visitFormComponents(new YavFormComponentVisitor(buffer, form)); // Build the call to the yav.init with the proper form name buffer.append("function yavInit() {\n"); buffer.append(" yav.init('" + formName + "', rules);\n"); buffer.append("}\n"); // Close the Yav script buffer.append("</script>\n"); // Write the generated script into the response Response response = RequestCycle.get().getResponse(); response.write(buffer.toString()); }
/** * @param response * @param id */ public static void writeOpenTag(final Response response, String id) { response.write("<script type=\"text/javascript\" "); if (id != null) { response.write("id=\"" + id + "\""); } response.write(">"); response.write(SCRIPT_CONTENT_PREFIX); }
@Override public void beforeRender(Component component) { FormComponent<?> fc = (FormComponent<?>) component; Response response = component.getResponse(); String error = (fc.isValid() ? "" : " error"); String id = getAjaxRegionMarkupId(component); response.write("<div id=\"" + id + "\" class=\"control-group" + error + "\">"); writeLabel(fc, response); response.write("<div class=\"controls\">"); }
protected void renderObject(O object, Response response, String criteria) { response.write( "<li idvalue=\"" + getIdValueForObject(object) + "\" textvalue=\"" + getTextValueForObject(object) + "\">"); renderChoice(object, response, criteria); response.write("</li>"); }
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>"); } }
/** On affiche le premier message correspondant au composant. */ @Override public void afterRender(Component component) { FormComponent<?> f = (FormComponent<?>) component; Response response = component.getResponse(); FeedbackMessages messages = f.getSession().getFeedbackMessages(); if (messages.hasMessageFor(component)) { IFeedbackMessageFilter filter = new ComponentFeedbackMessageFilter(component); response.write( "<span class=\"help-inline\">" + messages.messages(filter).get(0).getMessage() + "</span>"); } }
@Override protected void writeHeaderContribution(Response response) { if (headerBuffer.getContents().length() != 0) { response.write("<header-contribution>"); // we need to write response as CDATA and parse it on client, // because konqueror crashes when there is a <script> element response.write("<![CDATA[<head xmlns:wicket=\"http://wicket.apache.org\">"); response.write(encode(headerBuffer.getContents())); response.write("</head>]]>"); response.write("</header-contribution>"); } }
/** * First render the body of the component. And if it is the header component of a Page (compared * to a Panel or Border), then get the header sections from all component in the hierarchy and * render them as well. */ @Override public final void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { // We are able to automatically add <head> to the page if it is // missing. But we only want to add it, if we have content to be // written to its body. Thus we first write the output into a // StringResponse and if not empty, we copy it to the original // web response. // Temporarily replace the web response with a String response final Response webResponse = getResponse(); try { // Create a (string) response for all headers contributed by any component on the Page. final StringResponse response = new StringResponse(); getRequestCycle().setResponse(response); IHeaderResponse headerResponse = getHeaderResponse(); if (!response.equals(headerResponse.getResponse())) { getRequestCycle().setResponse(headerResponse.getResponse()); } // Render the header sections of all components on the page AbstractHeaderRenderStrategy.get() .renderHeader(this, new HeaderStreamState(markupStream, openTag), getPage()); // Close the header response before rendering the header container itself // See https://issues.apache.org/jira/browse/WICKET-3728 headerResponse.close(); // Cleanup extraneous CR and LF from the response CharSequence output = getCleanResponse(response); // Automatically add <head> if necessary if (output.length() > 0) { if (renderOpenAndCloseTags()) { webResponse.write("<head>"); } webResponse.write(output); if (renderOpenAndCloseTags()) { webResponse.write("</head>"); } } } finally { // Restore the original response getRequestCycle().setResponse(webResponse); } }
/** * @param invocation type of invocation tag, usually {@literal evaluate} or {@literal * priority-evaluate} * @param response * @param js */ private void writeEvaluation( final String invocation, final Response response, final CharSequence js) { response.write("<"); response.write(invocation); response.write(">"); response.write("<![CDATA["); response.write(encode(js)); response.write("]]>"); response.write("</"); response.write(invocation); response.write(">"); bodyBuffer.reset(); }
/** * 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"); }
@Override protected void writeFooter(Response response, String encoding) { response.write(END_ROOT_ELEMENT); }
/** * 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(">"); }
public static HttpServletResponse getHttpServletResponse(final Response response) { return (HttpServletResponse) response.getContainerResponse(); }
/** * Write the simple text to the response object surrounded by a script tag. * * @param response The HTTP: response * @param text The text to added in between the script tags * @param id Unique identifier of element */ public static void writeJavaScript(final Response response, final CharSequence text, String id) { writeOpenTag(response, id); response.write(text); writeCloseTag(response); }
/** * Render the visual portion of the assist. Usually the html representing the assist choice object * is written out to the response use {@link org.apache.wicket.Response#write(CharSequence)} * * @param object current assist choice * @param response * @param criteria */ protected void renderChoice(O object, Response response, String criteria) { response.write(getTextValueForObject(object)); }
@Override protected void writeComponent( Response response, String markupId, Component component, String encoding) { if (component.getRenderBodyOnly() == true) { throw new IllegalStateException( "A partial update is not possible for a component that has renderBodyOnly enabled. Component: " + component.toString()); } component.setOutputMarkupId(true); // Initialize temporary variables final Page page = component.findParent(Page.class); if (page == null) { // dont throw an exception but just ignore this component, somehow // it got removed from the page. LOG.warn( "Component '{}' with markupid: '{}' not rendered because it was already removed from page", component, markupId); return; } // substitute our encoding response for the old one so we can capture // component's markup in a manner safe for transport inside CDATA block Response oldResponse = RequestCycle.get().setResponse(bodyBuffer); try { bodyBuffer.reset(); page.startComponentRender(component); try { component.prepareForRender(); // render any associated headers of the component writeHeaderContribution(response, component); } catch (RuntimeException e) { try { component.afterRender(); } catch (RuntimeException e2) { // ignore this one could be a result off. } bodyBuffer.reset(); throw e; } try { component.render(); } catch (RuntimeException e) { bodyBuffer.reset(); throw e; } page.endComponentRender(component); } finally { // Restore original response RequestCycle.get().setResponse(oldResponse); } response.write("<component id=\""); response.write(markupId); response.write("\" ><![CDATA["); response.write(encode(bodyBuffer.getContents())); response.write("]]></component>"); bodyBuffer.reset(); }
/** @param response */ public static void writeCloseTag(final Response response) { response.write(SCRIPT_CONTENT_SUFFIX); response.write("</script>\n"); }
/** * @see Response#write(CharSequence) * @param script */ public void println(final CharSequence script) { response.write(script); }