/** * Determine the '{@code for}' attribute value for this tag, * autogenerating one if none specified. * @see #getFor() * @see #autogenerateFor() */ protected String resolveFor() throws JspException { if (StringUtils.hasText(this.forId)) { return getDisplayString(evaluate(FOR_ATTRIBUTE, this.forId)); } else { return autogenerateFor(); } }
/** * Autogenerate the '{@code for}' attribute value for this tag. * <p>The default implementation delegates to {@link #getPropertyPath()}, * deleting invalid characters (such as "[" or "]"). */ protected String autogenerateFor() throws JspException { return StringUtils.deleteAny(getPropertyPath(), "[]"); }
/** * Writes the opening '{@code label}' tag and forces a block tag so * that body content is written correctly. * @return {@link javax.servlet.jsp.tagext.Tag#EVAL_BODY_INCLUDE} */ @Override protected int writeTagContent(TagWriter tagWriter) throws JspException { tagWriter.startTag(LABEL_TAG); tagWriter.writeAttribute(FOR_ATTRIBUTE, resolveFor()); writeDefaultAttributes(tagWriter); tagWriter.forceBlock(); this.tagWriter = tagWriter; return EVAL_BODY_INCLUDE; }
@Test public void overrideFor() throws Exception { this.tag.setPath("name"); this.tag.setFor("myElement"); int startResult = this.tag.doStartTag(); int endResult = this.tag.doEndTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, startResult); assertEquals(Tag.EVAL_PAGE, endResult); String output = getOutput(); assertContainsAttribute(output, "for", "myElement"); // name attribute is not supported by <label/> assertAttributeNotPresent(output, "name"); // id attribute is supported, but we don't want it assertAttributeNotPresent(output, "id"); assertTrue(output.startsWith("<label ")); assertTrue(output.endsWith("</label>")); }
@Test public void simpleRenderWithDynamicAttributes() throws Exception { String dynamicAttribute1 = "attr1"; String dynamicAttribute2 = "attr2"; this.tag.setPath("name"); this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1); this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2); int startResult = this.tag.doStartTag(); int endResult = this.tag.doEndTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, startResult); assertEquals(Tag.EVAL_PAGE, endResult); String output = getOutput(); // we are using a nested path (see extendPageContext(..)), so... assertContainsAttribute(output, "for", "spouse.name"); assertContainsAttribute(output, dynamicAttribute1, dynamicAttribute1); assertContainsAttribute(output, dynamicAttribute2, dynamicAttribute2); // name attribute is not supported by <label/> assertAttributeNotPresent(output, "name"); // id attribute is supported, but we don't want it assertAttributeNotPresent(output, "id"); assertTrue(output.startsWith("<label ")); assertTrue(output.endsWith("</label>")); }
@Test public void simpleRender() throws Exception { this.tag.setPath("name"); int startResult = this.tag.doStartTag(); int endResult = this.tag.doEndTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, startResult); assertEquals(Tag.EVAL_PAGE, endResult); String output = getOutput(); // we are using a nested path (see extendPageContext(..)), so... assertContainsAttribute(output, "for", "spouse.name"); // name attribute is not supported by <label/> assertAttributeNotPresent(output, "name"); // id attribute is supported, but we don't want it assertAttributeNotPresent(output, "id"); assertTrue(output.startsWith("<label ")); assertTrue(output.endsWith("</label>")); }
@Test public void simpleRenderWithMapElement() throws Exception { this.tag.setPath("someMap[1]"); int startResult = this.tag.doStartTag(); int endResult = this.tag.doEndTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, startResult); assertEquals(Tag.EVAL_PAGE, endResult); String output = getOutput(); // we are using a nested path (see extendPageContext(..)), so... assertContainsAttribute(output, "for", "spouse.someMap1"); // name attribute is not supported by <label/> assertAttributeNotPresent(output, "name"); // id attribute is supported, but we don't want it assertAttributeNotPresent(output, "id"); assertTrue(output.startsWith("<label ")); assertTrue(output.endsWith("</label>")); }
/** * Determine the '{@code for}' attribute value for this tag, * autogenerating one if none specified. * @see #getFor() * @see #autogenerateFor() */ protected String resolveFor() throws JspException { if (StringUtils.hasText(this.forId)) { return getDisplayString(evaluate(FOR_ATTRIBUTE, this.forId)); } else { return autogenerateFor(); } }
/** * Writes the opening '{@code label}' tag and forces a block tag so * that body content is written correctly. * @return {@link javax.servlet.jsp.tagext.Tag#EVAL_BODY_INCLUDE} */ @Override protected int writeTagContent(TagWriter tagWriter) throws JspException { tagWriter.startTag(LABEL_TAG); tagWriter.writeAttribute(FOR_ATTRIBUTE, resolveFor()); writeDefaultAttributes(tagWriter); tagWriter.forceBlock(); this.tagWriter = tagWriter; return EVAL_BODY_INCLUDE; }
/** * Autogenerate the '{@code for}' attribute value for this tag. * <p>The default implementation delegates to {@link #getPropertyPath()}, * deleting invalid characters (such as "[" or "]"). */ protected String autogenerateFor() throws JspException { return StringUtils.deleteAny(getPropertyPath(), "[]"); }
/** * Determine the '{@code for}' attribute value for this tag, * autogenerating one if none specified. * @see #getFor() * @see #autogenerateFor() */ protected String resolveFor() throws JspException { if (StringUtils.hasText(this.forId)) { return getDisplayString(evaluate(FOR_ATTRIBUTE, this.forId)); } else { return autogenerateFor(); } }
/** * Writes the opening '{@code label}' tag and forces a block tag so * that body content is written correctly. * @return {@link javax.servlet.jsp.tagext.Tag#EVAL_BODY_INCLUDE} */ @Override protected int writeTagContent(TagWriter tagWriter) throws JspException { tagWriter.startTag(LABEL_TAG); tagWriter.writeAttribute(FOR_ATTRIBUTE, resolveFor()); writeDefaultAttributes(tagWriter); tagWriter.forceBlock(); this.tagWriter = tagWriter; return EVAL_BODY_INCLUDE; }
/** * Autogenerate the '{@code for}' attribute value for this tag. * <p>The default implementation delegates to {@link #getPropertyPath()}, * deleting invalid characters (such as "[" or "]"). */ protected String autogenerateFor() throws JspException { return StringUtils.deleteAny(getPropertyPath(), "[]"); }