javax.servlet.jsp.tagext.Tag Java Examples

The following examples show how to use javax.servlet.jsp.tagext.Tag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OptionTagEnumTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void withJavaEnum() throws Exception {
	GenericBean testBean = new GenericBean();
	testBean.setCustomEnum(CustomEnum.VALUE_1);
	getPageContext().getRequest().setAttribute("testBean", testBean);
	String selectName = "testBean.customEnum";
	getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));

	this.tag.setValue("VALUE_1");

	int result = this.tag.doStartTag();
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
	result = this.tag.doEndTag();
	assertEquals(Tag.EVAL_PAGE, result);

	String output = getWriter().toString();

	assertOptionTagOpened(output);
	assertOptionTagClosed(output);
	assertContainsAttribute(output, "value", "VALUE_1");
	assertContainsAttribute(output, "selected", "selected");
}
 
Example #2
Source File: CheckboxTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void collectionOfPetsAsStringNotSelected() throws Exception {
	this.tag.setPath("pets");
	this.tag.setValue("Santa's Little Helper");

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("pets", checkboxElement.attribute("name").getValue());
	assertNull(checkboxElement.attribute("checked"));
}
 
Example #3
Source File: DumpTagTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoEndTagDefaultPageScope() throws Exception {
    this.context.setAttribute("testAttribute01", "testValue01", PageContext.PAGE_SCOPE);
    this.context.setAttribute("anotherAttribute02", "finalValue02", PageContext.PAGE_SCOPE);
    this.context.setAttribute("badAttribute03", "skippedValue03", PageContext.SESSION_SCOPE);

    final int returnValue = this.tag.doEndTag();
    assertEquals("The return value is not correct.", Tag.EVAL_PAGE, returnValue);

    this.writer.flush();
    final String output = new String(this.output.toByteArray(), UTF8);
    assertEquals("The output is not correct.",
            "<dl>" +
                    "<dt><code>testAttribute01</code></dt><dd><code>testValue01</code></dd>" +
                    "<dt><code>anotherAttribute02</code></dt><dd><code>finalValue02</code></dd>" +
                    "</dl>", output);
}
 
Example #4
Source File: SelectTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void multipleExplicitlyFalse() throws Exception {
	this.tag.setPath("name");
	this.tag.setItems(Country.getCountries());
	this.tag.setItemValue("isoCode");
	this.tag.setMultiple("false");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();
	assertEquals(1, rootElement.elements().size());

	Element selectElement = rootElement.element("select");
	assertEquals("select", selectElement.getName());
	assertEquals("name", selectElement.attribute("name").getValue());
	assertNull(selectElement.attribute("multiple"));

	List children = selectElement.elements();
	assertEquals("Incorrect number of children", 4, children.size());
}
 
Example #5
Source File: OptionTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void withCustomObjectNotSelected() throws Exception {
	String selectName = "testBean.someNumber";
	getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
	this.tag.setValue(new Float(12.35));
	this.tag.setLabel("GBP 12.35");
	int result = this.tag.doStartTag();
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
	result = this.tag.doEndTag();
	assertEquals(Tag.EVAL_PAGE, result);

	String output = getOutput();

	assertOptionTagOpened(output);
	assertOptionTagClosed(output);
	assertContainsAttribute(output, "value", "12.35");
	assertAttributeNotPresent(output, "selected");
	assertBlockTagContains(output, "GBP 12.35");
}
 
Example #6
Source File: GroupTitleLineRenderer.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void renderGroupActions(PageContext pageContext, Tag parentTag) throws JspException {
    List<? extends AccountingLineViewActionDefinition> accountingLineGroupActions = accountingLineGroupDefinition.getAccountingLineGroupActions();
    if (!this.isGroupActionsRendered() || accountingLineGroupActions == null || accountingLineGroupActions.isEmpty()) {
        return;
    }

    List<AccountingLineViewAction> viewActions = new ArrayList<AccountingLineViewAction>();
    for (AccountingLineViewActionDefinition action : accountingLineGroupActions) {
        String actionMethod = action.getActionMethod();
        String actionLabel = action.getActionLabel();
        String imageName = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString("externalizable.images.url") + action.getImageName();

        AccountingLineViewAction viewAction = new AccountingLineViewAction(actionMethod, actionLabel, imageName);
        viewActions.add(viewAction);
    }

    if (!viewActions.isEmpty()) {
        ActionsRenderer actionsRenderer = new ActionsRenderer();
        actionsRenderer.setTagBeginning(" ");
        actionsRenderer.setTagEnding(" ");
        actionsRenderer.setPostButtonSpacing(" ");
        actionsRenderer.setActions(viewActions);
        actionsRenderer.render(pageContext, parentTag);
        actionsRenderer.clear();
    }
}
 
Example #7
Source File: BindTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void bindTagWithIndexedProperties() throws JspException {
	PageContext pc = createPageContext();
	IndexedTestBean tb = new IndexedTestBean();
	Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
	errors.rejectValue("array[0]", "code1", "message1");
	errors.rejectValue("array[0]", "code2", "message2");
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb.array[0]");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertTrue("Correct expression", "array[0]".equals(status.getExpression()));
	assertTrue("Value is TestBean", status.getValue() instanceof TestBean);
	assertTrue("Correct value", "name0".equals(((TestBean) status.getValue()).getName()));
	assertTrue("Correct isError", status.isError());
	assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
	assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
	assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
	assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
	assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0]));
	assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
}
 
Example #8
Source File: DynamicNameLabelRenderer.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @see org.kuali.kfs.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag, org.kuali.rice.krad.bo.BusinessObject)
 */
public void render(PageContext pageContext, Tag parentTag) throws JspException {
    JspWriter out = pageContext.getOut();
    try {
        out.write("<br />");
        out.write("<div id=\""+fieldName+".div\" class=\"fineprint\">");
        if (!StringUtils.isBlank(fieldValue)) {
            out.write(fieldValue);
        }
        out.write("</div>");
        
        if (!StringUtils.isBlank(fieldValue)) {
            renderValuePersistingTag(pageContext, parentTag);
        }
    }
    catch (IOException ioe) {
        throw new JspException("Difficulty rendering a dynamic field label", ioe);
    }
}
 
Example #9
Source File: MessageTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void messageTagWithCodeAndNestedArguments() throws JspException {
	PageContext pc = createPageContext();
	final StringBuffer message = new StringBuffer();
	MessageTag tag = new MessageTag() {
		@Override
		protected void writeMessage(String msg) {
			message.append(msg);
		}
	};
	tag.setPageContext(pc);
	tag.setCode("testArgs");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	tag.addArgument("arg1");
	tag.addArgument(6);
	assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
	assertEquals("Correct message", "test arg1 message 6", message.toString());
}
 
Example #10
Source File: RadioButtonTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void collectionOfPetsNotSelected() throws Exception {
	this.tag.setPath("pets");
	this.tag.setValue(new Pet("Santa's Little Helper"));

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("radio", checkboxElement.attribute("type").getValue());
	assertEquals("pets", checkboxElement.attribute("name").getValue());
	assertEquals("Santa's Little Helper", checkboxElement.attribute("value").getValue());
	assertNull(checkboxElement.attribute("checked"));
}
 
Example #11
Source File: SetLoggerTagTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoEndTagStringVarRequestScope() throws Exception {
    this.tag.setLogger("testDoEndTagStringVarRequestScope");

    this.tag.setVar("goodbyeCruelWorld");
    this.tag.setScope("request");

    assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
    assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
    assertNull("The default logger should still be null.", TagUtils.getDefaultLogger(this.context));

    final Object attribute = this.context.getAttribute("goodbyeCruelWorld", PageContext.REQUEST_SCOPE);
    assertNotNull("The attribute should not be null.", attribute);
    assertTrue("The attribute should be a Log4jTaglibLogger.", attribute instanceof Log4jTaglibLogger);

    final Log4jTaglibLogger logger = (Log4jTaglibLogger)attribute;
    assertEquals("The logger name is not correct.", "testDoEndTagStringVarRequestScope", logger.getName());
}
 
Example #12
Source File: RequireTagTest.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
public void testMixin() {

        boolean flag = false;
        try {
            rt.setAcl("true_test()");
            rt.setMixins("throws.class.not.found.exception," +
                         BooleanAclHandler.class.getName());

            tth.assertDoStartTag(Tag.EVAL_BODY_INCLUDE);
            flag = true;
        }
        catch (JspException je) {
            assertFalse(flag);
        }
        catch (Exception e) {
            fail(e.toString());
        }
    }
 
Example #13
Source File: OptionsTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void withItemsNullReference() throws Exception {
	getPageContext().setAttribute(
			SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));

	this.tag.setItems(Collections.emptyList());
	this.tag.setItemValue("isoCode");
	this.tag.setItemLabel("name");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);
	String output = getOutput();
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();

	List children = rootElement.elements();
	assertEquals("Incorrect number of children", 0, children.size());
}
 
Example #14
Source File: OptionTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void withCustomObjectNotSelected() throws Exception {
	String selectName = "testBean.someNumber";
	BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
	getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
	this.tag.setValue(new Float(12.35));
	this.tag.setLabel("GBP 12.35");
	int result = this.tag.doStartTag();
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
	result = this.tag.doEndTag();
	assertEquals(Tag.EVAL_PAGE, result);

	String output = getOutput();

	assertOptionTagOpened(output);
	assertOptionTagClosed(output);
	assertContainsAttribute(output, "value", "12.35");
	assertAttributeNotPresent(output, "selected");
	assertBlockTagContains(output, "GBP 12.35");
}
 
Example #15
Source File: OptionTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void canBeDisabledEvenWhenSelected() throws Exception {
	String selectName = "testBean.name";
	BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
	getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
	this.tag.setValue("bar");
	this.tag.setLabel("Bar");
	this.tag.setDisabled(true);
	int result = this.tag.doStartTag();
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
	result = this.tag.doEndTag();
	assertEquals(Tag.EVAL_PAGE, result);

	String output = getOutput();

	assertOptionTagOpened(output);
	assertOptionTagClosed(output);
	assertContainsAttribute(output, "value", "bar");
	assertContainsAttribute(output, "disabled", "disabled");
	assertBlockTagContains(output, "Bar");
}
 
Example #16
Source File: MessageTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void messageTagWithTextAndHtmlEscapeAndJavaScriptEscape() throws JspException {
	PageContext pc = createPageContext();
	final StringBuffer message = new StringBuffer();
	MessageTag tag = new MessageTag() {
		@Override
		protected void writeMessage(String msg) {
			message.append(msg);
		}
	};
	tag.setPageContext(pc);
	tag.setText("' test & text \\");
	tag.setHtmlEscape(true);
	tag.setJavaScriptEscape(true);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
	assertEquals("Correct message", "&#39; test &amp; text \\\\", message.toString());
}
 
Example #17
Source File: SetLoggerTagTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoEndTagStringVarPageScope() throws Exception {
    this.tag.setLogger("testDoEndTagStringVarPageScope");

    this.tag.setVar("goodbyeCruelWorld");

    assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
    assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
    assertNull("The default logger should still be null.", TagUtils.getDefaultLogger(this.context));

    final Object attribute = this.context.getAttribute("goodbyeCruelWorld", PageContext.PAGE_SCOPE);
    assertNotNull("The attribute should not be null.", attribute);
    assertTrue("The attribute should be a Log4jTaglibLogger.", attribute instanceof Log4jTaglibLogger);

    final Log4jTaglibLogger logger = (Log4jTaglibLogger)attribute;
    assertEquals("The logger name is not correct.", "testDoEndTagStringVarPageScope", logger.getName());
}
 
Example #18
Source File: MessageTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void messageTagWithCodeAndObjectArgument() throws JspException {
	PageContext pc = createPageContext();
	final StringBuffer message = new StringBuffer();
	MessageTag tag = new MessageTag() {
		@Override
		protected void writeMessage(String msg) {
			message.append(msg);
		}
	};
	tag.setPageContext(pc);
	tag.setCode("testArgs");
	tag.setArguments(5);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
	assertEquals("Correct message", "test 5 message {1}", message.toString());
}
 
Example #19
Source File: ErrorsTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void withExplicitWhitespaceBodyContent() throws Exception {
	this.tag.setBodyContent(new MockBodyContent("\t\n   ", getWriter()));

	// construct an errors instance of the tag
	TestBean target = new TestBean();
	target.setName("Rob Harrop");
	Errors errors = new BeanPropertyBindingResult(target, COMMAND_NAME);
	errors.rejectValue("name", "some.code", "Default Message");

	exposeBindingResult(errors);

	int result = this.tag.doStartTag();
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);

	result = this.tag.doEndTag();
	assertEquals(Tag.EVAL_PAGE, result);

	String output = getOutput();
	assertElementTagOpened(output);
	assertElementTagClosed(output);

	assertContainsAttribute(output, "id", "name.errors");
	assertBlockTagContains(output, "Default Message");
}
 
Example #20
Source File: CheckboxTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void collectionOfPetsAsStringNotSelected() throws Exception {
	this.tag.setPath("pets");
	this.tag.setValue("Santa's Little Helper");

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("pets", checkboxElement.attribute("name").getValue());
	assertNull(checkboxElement.attribute("checked"));
}
 
Example #21
Source File: MessageTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void messageTagWithCodeAndObjectArgument() throws JspException {
	PageContext pc = createPageContext();
	final StringBuffer message = new StringBuffer();
	MessageTag tag = new MessageTag() {
		@Override
		protected void writeMessage(String msg) {
			message.append(msg);
		}
	};
	tag.setPageContext(pc);
	tag.setCode("testArgs");
	tag.setArguments(5);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
	assertEquals("Correct message", "test 5 message {1}", message.toString());
}
 
Example #22
Source File: NavDialogMenuTagTest.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
public void testIOExceptionHandling() {
    TagTestHelper tth = TagTestUtils.setupTagTest(nmt, url);

    boolean exceptionNotThrown = false;

    try {
        // need to override the JspWriter
        RhnMockExceptionJspWriter out = new RhnMockExceptionJspWriter();
        tth.getPageContext().setJspWriter(out);

        // ok let's test the tag
        setupTag(nmt, 10, 4, NAV_XML, DIALOG_NAV);
        tth.assertDoStartTag(Tag.SKIP_BODY);
        exceptionNotThrown = true;
    }
    catch (JspException e) {
        assertFalse(exceptionNotThrown);
    }
}
 
Example #23
Source File: AccountingLineViewField.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Renders a dynamic field label
 *
 * @param pageContext the page context to render to
 * @param parentTag the parent tag requesting this rendering
 * @param accountingLine the line which owns the field being rendered
 * @param accountingLinePropertyPath the path from the form to the accounting line
 */
protected void renderDynamicNameLabel(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
    AccountingLine accountingLine = renderingContext.getAccountingLine();
    String accountingLinePropertyPath = renderingContext.getAccountingLinePropertyPath();

    DynamicNameLabelRenderer renderer = new DynamicNameLabelRenderer();
    if (definition.getDynamicNameLabelGenerator() != null) {
        renderer.setFieldName(definition.getDynamicNameLabelGenerator().getDynamicNameLabelFieldName(accountingLine, accountingLinePropertyPath));
        renderer.setFieldValue(definition.getDynamicNameLabelGenerator().getDynamicNameLabelValue(accountingLine, accountingLinePropertyPath));
    }
    else {
        if (!StringUtils.isBlank(getField().getPropertyValue())) {
            if (getField().isSecure()) {
                renderer.setFieldValue(getField().getDisplayMask().maskValue(getField().getPropertyValue()));
            }
            else {
                renderer.setFieldValue(getDynamicNameLabelDisplayedValue(accountingLine));
            }
        }
        renderer.setFieldName(accountingLinePropertyPath + "." + definition.getDynamicLabelProperty());
    }
    renderer.render(pageContext, parentTag);
    renderer.clear();
}
 
Example #24
Source File: MessageTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void messageTagWithCodeAndArgumentAndNestedArgument() throws JspException {
	PageContext pc = createPageContext();
	final StringBuffer message = new StringBuffer();
	MessageTag tag = new MessageTag() {
		@Override
		protected void writeMessage(String msg) {
			message.append(msg);
		}
	};
	tag.setPageContext(pc);
	tag.setCode("testArgs");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	tag.setArguments(5);
	tag.addArgument(7);
	assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
	assertEquals("Correct message", "test 5 message 7", message.toString());
}
 
Example #25
Source File: MessageTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void messageTagWithTextAndJavaScriptEscape() throws JspException {
	PageContext pc = createPageContext();
	final StringBuffer message = new StringBuffer();
	MessageTag tag = new MessageTag() {
		@Override
		protected void writeMessage(String msg) {
			message.append(msg);
		}
	};
	tag.setPageContext(pc);
	tag.setText("' test & text \\");
	tag.setJavaScriptEscape(true);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
	assertEquals("Correct message", "\\' test & text \\\\", message.toString());
}
 
Example #26
Source File: OptionTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void renderSelected() throws Exception {
	String selectName = "testBean.name";
	BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
	getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
	this.tag.setId("myOption");
	this.tag.setValue("foo");
	this.tag.setLabel("Foo");
	int result = this.tag.doStartTag();
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
	result = this.tag.doEndTag();
	assertEquals(Tag.EVAL_PAGE, result);

	String output = getOutput();

	assertOptionTagOpened(output);
	assertOptionTagClosed(output);
	assertContainsAttribute(output, "id", "myOption");
	assertContainsAttribute(output, "value", "foo");
	assertContainsAttribute(output, "selected", "selected");
	assertBlockTagContains(output, "Foo");
}
 
Example #27
Source File: OptionTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void withNoLabel() throws Exception {
	String selectName = "testBean.name";
	BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
	getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
	this.tag.setValue("bar");
	this.tag.setCssClass("myClass");
	this.tag.setOnclick("CLICK");
	int result = this.tag.doStartTag();
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
	result = this.tag.doEndTag();
	assertEquals(Tag.EVAL_PAGE, result);

	String output = getOutput();

	assertOptionTagOpened(output);
	assertOptionTagClosed(output);
	assertContainsAttribute(output, "value", "bar");
	assertContainsAttribute(output, "class", "myClass");
	assertContainsAttribute(output, "onclick", "CLICK");
	assertBlockTagContains(output, "bar");
}
 
Example #28
Source File: OptionTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void withCustomObjectSelected() throws Exception {
	String selectName = "testBean.someNumber";
	BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
	getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
	this.tag.setValue(new Float(12.34));
	this.tag.setLabel("GBP 12.34");
	int result = this.tag.doStartTag();
	assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
	result = this.tag.doEndTag();
	assertEquals(Tag.EVAL_PAGE, result);

	String output = getOutput();

	assertOptionTagOpened(output);
	assertOptionTagClosed(output);
	assertContainsAttribute(output, "value", "12.34");
	assertContainsAttribute(output, "selected", "selected");
	assertBlockTagContains(output, "GBP 12.34");
}
 
Example #29
Source File: MessageTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void messageTagWithCodeAndArgumentAndNestedArgument() throws JspException {
	PageContext pc = createPageContext();
	final StringBuffer message = new StringBuffer();
	MessageTag tag = new MessageTag() {
		@Override
		protected void writeMessage(String msg) {
			message.append(msg);
		}
	};
	tag.setPageContext(pc);
	tag.setCode("testArgs");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	tag.setArguments(5);
	tag.addArgument(7);
	assertEquals("Correct doEndTag return value", Tag.EVAL_PAGE, tag.doEndTag());
	assertEquals("Correct message", "test 5 message 7", message.toString());
}
 
Example #30
Source File: PasswordInputTagTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * https://jira.spring.io/browse/SPR-2866
 */
@Test
public void passwordValueIsNotRenderedIfShowPasswordAttributeIsSetToFalse() throws Exception {
	this.getTag().setPath("name");
	this.getPasswordTag().setShowPassword(false);

	assertEquals(Tag.SKIP_BODY, this.getTag().doStartTag());

	String output = getOutput();
	assertTagOpened(output);
	assertTagClosed(output);

	assertContainsAttribute(output, "type", getType());
	assertValueAttribute(output, "");
}