本文整理汇总了Java中javax.servlet.jsp.tagext.BodyTag类的典型用法代码示例。如果您正苦于以下问题:Java BodyTag类的具体用法?Java BodyTag怎么用?Java BodyTag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BodyTag类属于javax.servlet.jsp.tagext包,在下文中一共展示了BodyTag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReplacement
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
/**
* Sets the replacement target and replacement String on the tag, then calls
* doAfterBody(). Most of the assertion work is done in endReplacement().
*/
public void testReplacement() throws Exception
{
//set the target and the String to replace it with
this.tag.setTarget("@[email protected]");
this.tag.setReplacement("replacement");
//add the tag's body by writing to the BodyContent object created in
//setUp()
this.tagContent.println("@[email protected] is now @[email protected]");
this.tagContent.println("@[email protected][email protected]@");
//none of the other life cycle methods need to be implemented, so they
//do not need to be called.
int result = this.tag.doAfterBody();
assertEquals(BodyTag.SKIP_BODY, result);
}
示例2: CustomTag
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
public CustomTag(String qName, String prefix, String localName, String uri, Attributes attrs,
Attributes nonTaglibXmlnsAttrs, Attributes taglibAttrs, Mark start, Node parent, TagInfo tagInfo,
Class<?> tagHandlerClass) {
super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent);
this.uri = uri;
this.prefix = prefix;
this.tagInfo = tagInfo;
this.tagHandlerClass = tagHandlerClass;
this.customNestingLevel = makeCustomNestingLevel();
this.childInfo = new ChildInfo();
this.implementsIterationTag = IterationTag.class.isAssignableFrom(tagHandlerClass);
this.implementsBodyTag = BodyTag.class.isAssignableFrom(tagHandlerClass);
this.implementsTryCatchFinally = TryCatchFinally.class.isAssignableFrom(tagHandlerClass);
this.implementsSimpleTag = SimpleTag.class.isAssignableFrom(tagHandlerClass);
this.implementsDynamicAttributes = DynamicAttributes.class.isAssignableFrom(tagHandlerClass);
this.implementsJspIdConsumer = JspIdConsumer.class.isAssignableFrom(tagHandlerClass);
}
示例3: withExplicitNonWhitespaceBodyContent
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void withExplicitNonWhitespaceBodyContent() throws Exception {
String mockContent = "This is some explicit body content";
this.tag.setBodyContent(new MockBodyContent(mockContent, 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);
assertEquals(mockContent, getOutput());
}
示例4: withExplicitWhitespaceBodyContent
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@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");
}
示例5: withExplicitEmptyWhitespaceBodyContent
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void withExplicitEmptyWhitespaceBodyContent() throws Exception {
this.tag.setBodyContent(new MockBodyContent("", 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");
}
示例6: withErrors
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void withErrors() throws Exception {
// 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");
errors.rejectValue("name", "too.short", "Too Short");
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, "<br/>");
assertBlockTagContains(output, "Default Message");
assertBlockTagContains(output, "Too Short");
}
示例7: withEscapedErrors
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void withEscapedErrors() throws Exception {
// 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");
errors.rejectValue("name", "too.short", "Too & Short");
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, "<br/>");
assertBlockTagContains(output, "Default <> Message");
assertBlockTagContains(output, "Too & Short");
}
示例8: asBodyTag
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void asBodyTag() throws Exception {
Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
errors.rejectValue("name", "some.code", "Default Message");
errors.rejectValue("name", "too.short", "Too Short");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
String bodyContent = "Foo";
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
this.tag.doEndTag();
this.tag.doFinally();
assertEquals(bodyContent, getOutput());
assertNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
}
示例9: asBodyTagWithExistingMessagesAttribute
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void asBodyTagWithExistingMessagesAttribute() throws Exception {
String existingAttribute = "something";
getPageContext().setAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, existingAttribute);
Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
errors.rejectValue("name", "some.code", "Default Message");
errors.rejectValue("name", "too.short", "Too Short");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
assertTrue(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE) instanceof List);
String bodyContent = "Foo";
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
this.tag.doEndTag();
this.tag.doFinally();
assertEquals(bodyContent, getOutput());
assertEquals(existingAttribute, getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
}
示例10: asBodyTagWithErrorsAndExistingMessagesAttributeInNonPageScopeAreNotClobbered
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
/**
* https://jira.spring.io/browse/SPR-2788
*/
@Test
public void asBodyTagWithErrorsAndExistingMessagesAttributeInNonPageScopeAreNotClobbered() throws Exception {
String existingAttribute = "something";
getPageContext().setAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, existingAttribute, PageContext.APPLICATION_SCOPE);
Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME");
errors.rejectValue("name", "some.code", "Default Message");
errors.rejectValue("name", "too.short", "Too Short");
exposeBindingResult(errors);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
assertTrue(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE) instanceof List);
String bodyContent = "Foo";
this.tag.setBodyContent(new MockBodyContent(bodyContent, getWriter()));
this.tag.doEndTag();
this.tag.doFinally();
assertEquals(bodyContent, getOutput());
assertEquals(existingAttribute,
getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE, PageContext.APPLICATION_SCOPE));
}
示例11: canBeDisabledEvenWhenSelected
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void canBeDisabledEvenWhenSelected() throws Exception {
String selectName = "testBean.name";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
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");
}
示例12: renderNotSelected
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void renderNotSelected() throws Exception {
String selectName = "testBean.name";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
this.tag.setValue("bar");
this.tag.setLabel("Bar");
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");
assertBlockTagContains(output, "Bar");
}
示例13: renderWithDynamicAttributes
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void renderWithDynamicAttributes() throws Exception {
String dynamicAttribute1 = "attr1";
String dynamicAttribute2 = "attr2";
String selectName = "testBean.name";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
this.tag.setValue("bar");
this.tag.setLabel("Bar");
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);
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, dynamicAttribute1, dynamicAttribute1);
assertContainsAttribute(output, dynamicAttribute2, dynamicAttribute2);
assertBlockTagContains(output, "Bar");
}
示例14: renderSelected
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void renderSelected() throws Exception {
String selectName = "testBean.name";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
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");
}
示例15: withNoLabel
import javax.servlet.jsp.tagext.BodyTag; //导入依赖的package包/类
@Test
public void withNoLabel() throws Exception {
String selectName = "testBean.name";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
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");
}