use of jakarta.servlet.jsp.PageContext in project tomcat by apache.
the class JspFactoryImpl method internalGetPageContext.
private PageContext internalGetPageContext(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoflush) {
PageContext pc;
if (poolSize > 0) {
PageContextPool pool = localPool.get();
if (pool == null) {
pool = new PageContextPool(poolSize);
localPool.set(pool);
}
pc = pool.get();
if (pc == null) {
pc = new PageContextImpl();
}
} else {
pc = new PageContextImpl();
}
try {
pc.initialize(servlet, request, response, errorPageURL, needsSession, bufferSize, autoflush);
} catch (IOException ioe) {
// Implementation never throws IOE but can't change the signature
// since it is part of the JSP API
}
return pc;
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class TagIdGeneratorTests method assertNextId.
private void assertNextId() {
PageContext pageContext = new MockPageContext();
assertThat(TagIdGenerator.nextId("foo", pageContext)).isEqualTo("foo1");
assertThat(TagIdGenerator.nextId("foo", pageContext)).isEqualTo("foo2");
assertThat(TagIdGenerator.nextId("foo", pageContext)).isEqualTo("foo3");
assertThat(TagIdGenerator.nextId("foo", pageContext)).isEqualTo("foo4");
assertThat(TagIdGenerator.nextId("bar", pageContext)).isEqualTo("bar1");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method nestedPathDoStartTagInternalWithNesting.
@Test
void nestedPathDoStartTagInternalWithNesting() throws JspException {
PageContext pc = createPageContext();
NestedPathTag tag = new NestedPathTag();
tag.setPath("foo");
tag.setPageContext(pc);
tag.doStartTag();
assertThat(pc.getAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE)).isEqualTo("foo.");
NestedPathTag anotherTag = new NestedPathTag();
anotherTag.setPageContext(pc);
anotherTag.setPath("bar");
anotherTag.doStartTag();
assertThat(pc.getAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE)).isEqualTo("foo.bar.");
NestedPathTag yetAnotherTag = new NestedPathTag();
yetAnotherTag.setPageContext(pc);
yetAnotherTag.setPath("boo");
yetAnotherTag.doStartTag();
assertThat(pc.getAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE)).isEqualTo("foo.bar.boo.");
yetAnotherTag.doEndTag();
NestedPathTag andAnotherTag = new NestedPathTag();
andAnotherTag.setPageContext(pc);
andAnotherTag.setPath("boo2");
andAnotherTag.doStartTag();
assertThat(pc.getAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE)).isEqualTo("foo.bar.boo2.");
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithFieldErrors.
@Test
void bindTagWithFieldErrors() throws JspException {
PageContext pc = createPageContext();
TestBean tb = new TestBean();
tb.setName("name1");
Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
errors.rejectValue("name", "code1", "message & 1");
errors.rejectValue("name", "code2", "message2");
errors.rejectValue("age", "code2", "message2");
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.name");
tag.setHtmlEscape(true);
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat("name".equals(status.getExpression())).as("Correct expression").isTrue();
assertThat("name1".equals(status.getValue())).as("Correct value").isTrue();
assertThat("name1".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 2).as("Correct errorCodes").isTrue();
assertThat(status.getErrorMessages().length == 2).as("Correct errorMessages").isTrue();
assertThat("code1".equals(status.getErrorCode())).as("Correct errorCode").isTrue();
assertThat("code1".equals(status.getErrorCodes()[0])).as("Correct errorCode").isTrue();
assertThat("code2".equals(status.getErrorCodes()[1])).as("Correct errorCode").isTrue();
assertThat("message & 1".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("message & 1".equals(status.getErrorMessages()[0])).as("Correct errorMessage").isTrue();
assertThat("message2".equals(status.getErrorMessages()[1])).as("Correct errorMessage").isTrue();
assertThat("message & 1 - message2".equals(status.getErrorMessagesAsString(" - "))).as("Correct errorMessagesAsString").isTrue();
tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.age");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat("age".equals(status.getExpression())).as("Correct expression").isTrue();
assertThat(Integer.valueOf(0).equals(status.getValue())).as("Correct value").isTrue();
assertThat("0".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 1).as("Correct errorCodes").isTrue();
assertThat(status.getErrorMessages().length == 1).as("Correct errorMessages").isTrue();
assertThat("code2".equals(status.getErrorCode())).as("Correct errorCode").isTrue();
assertThat("message2".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("message2".equals(status.getErrorMessagesAsString(" - "))).as("Correct errorMessagesAsString").isTrue();
tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.*");
assertThat(tag.doStartTag() == Tag.EVAL_BODY_INCLUDE).as("Correct doStartTag return value").isTrue();
status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status != null).as("Has status variable").isTrue();
assertThat("*".equals(status.getExpression())).as("Correct expression").isTrue();
assertThat(status.getValue() == null).as("Correct value").isTrue();
assertThat("".equals(status.getDisplayValue())).as("Correct displayValue").isTrue();
assertThat(status.isError()).as("Correct isError").isTrue();
assertThat(status.getErrorCodes().length == 3).as("Correct errorCodes").isTrue();
assertThat(status.getErrorMessages().length == 3).as("Correct errorMessages").isTrue();
assertThat("code1".equals(status.getErrorCode())).as("Correct errorCode").isTrue();
assertThat("code1".equals(status.getErrorCodes()[0])).as("Correct errorCode").isTrue();
assertThat("code2".equals(status.getErrorCodes()[1])).as("Correct errorCode").isTrue();
assertThat("code2".equals(status.getErrorCodes()[2])).as("Correct errorCode").isTrue();
assertThat("message & 1".equals(status.getErrorMessage())).as("Correct errorMessage").isTrue();
assertThat("message & 1".equals(status.getErrorMessages()[0])).as("Correct errorMessage").isTrue();
assertThat("message2".equals(status.getErrorMessages()[1])).as("Correct errorMessage").isTrue();
assertThat("message2".equals(status.getErrorMessages()[2])).as("Correct errorMessage").isTrue();
}
use of jakarta.servlet.jsp.PageContext in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithFieldButWithoutErrorsInstance.
@Test
void bindTagWithFieldButWithoutErrorsInstance() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.name");
pc.getRequest().setAttribute("tb", new TestBean("juergen&eva", 99));
tag.doStartTag();
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status.getExpression()).isEqualTo("name");
assertThat(status.getValue()).isEqualTo("juergen&eva");
}
Aggregations