本文整理匯總了Java中org.springframework.web.servlet.view.AbstractView類的典型用法代碼示例。如果您正苦於以下問題:Java AbstractView類的具體用法?Java AbstractView怎麽用?Java AbstractView使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AbstractView類屬於org.springframework.web.servlet.view包,在下文中一共展示了AbstractView類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveViewName
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Override
public View resolveViewName(final String viewName, Locale locale) throws Exception {
return new AbstractView () {
@Override
public String getContentType() {
return null;
}
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) throws Exception {
for (String key : attrsToValidate.keySet()) {
assertTrue("Model should contain attribute named " + key, model.containsKey(key));
assertEquals(attrsToValidate.get(key), model.get(key));
validatedAttrCount++;
}
}
};
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:UriTemplateServletAnnotationControllerHandlerMethodTests.java
示例2: initialize
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
protected <V extends AbstractView> V initialize (V view) {
if (attributes != null && !attributes.isEmpty ())
view.setAttributesMap (attributes);
if (applicationContext != null)
view.setApplicationContext (applicationContext);
if (beanName != null)
view.setBeanName (beanName);
if (contentType != null)
view.setContentType (contentType);
view.setExposePathVariables (exposePathVariables);
if (requestContextAttribute != null)
view.setRequestContextAttribute (requestContextAttribute);
if (servletContext != null)
view.setServletContext (servletContext);
return view;
}
示例3: validTemplateName
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Test
public void validTemplateName() throws Exception {
FreeMarkerView fv = new FreeMarkerView();
WebApplicationContext wac = mock(WebApplicationContext.class);
MockServletContext sc = new MockServletContext();
Map<String, FreeMarkerConfig> configs = new HashMap<String, FreeMarkerConfig>();
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setConfiguration(new TestConfiguration());
configs.put("configurer", configurer);
given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(configs);
given(wac.getServletContext()).willReturn(sc);
fv.setUrl("templateName");
fv.setApplicationContext(wac);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.US);
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
HttpServletResponse response = new MockHttpServletResponse();
Map<String, Object> model = new HashMap<String, Object>();
model.put("myattr", "myvalue");
fv.render(model, request, response);
assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, response.getContentType());
}
示例4: error
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Bean
public View error() {
return new AbstractView() {
@Override
protected void renderMergedOutputModel(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.getWriter().write("ERROR_BEAN");
}
};
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:BasicErrorControllerMockMvcTests.java
示例5: jsonView
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Bean
public View jsonView() {
return new AbstractView() {
@Override
protected void renderMergedOutputModel(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.getOutputStream().write("Hello World".getBytes());
}
};
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:13,代碼來源:WebMvcAutoConfigurationTests.java
示例6: resolveViewName
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
switch (viewName) {
case "owner/index":
AbstractView view = new OwnerPdfView();
view.setBeanName(viewName);
return view;
}
return null;
}
示例7: resolveViewName
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
switch (viewName) {
case "owner/index":
AbstractView view = new OwnerAtomFeedView();
view.setBeanName(viewName);
return view;
}
return null;
}
示例8: resolveViewName
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
switch (viewName) {
case "owner/index":
AbstractView view = new OwnerExcelView();
view.setBeanName(viewName);
return view;
}
return null;
}
示例9: testValidTemplateName
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Test
public void testValidTemplateName() throws Exception {
FreeMarkerView fv = new FreeMarkerView();
WebApplicationContext wac = mock(WebApplicationContext.class);
MockServletContext sc = new MockServletContext();
Map configs = new HashMap();
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setConfiguration(new TestConfiguration());
configs.put("configurer", configurer);
given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(configs);
given(wac.getServletContext()).willReturn(sc);
fv.setUrl("templateName");
fv.setApplicationContext(wac);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.US);
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
HttpServletResponse response = new MockHttpServletResponse();
Map model = new HashMap();
model.put("myattr", "myvalue");
fv.render(model, request, response);
assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, response.getContentType());
}
示例10: testExposeHelpers
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Test
public void testExposeHelpers() throws Exception {
final String templateName = "test.vm";
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
final Template expectedTemplate = new Template();
VelocityConfig vc = new VelocityConfig() {
@Override
public VelocityEngine getVelocityEngine() {
return new TestVelocityEngine(templateName, expectedTemplate);
}
};
Map<String, VelocityConfig> configurers = new HashMap<String, VelocityConfig>();
configurers.put("velocityConfigurer", vc);
given(wac.getBeansOfType(VelocityConfig.class, true, false)).willReturn(configurers);
// let it ask for locale
HttpServletRequest req = mock(HttpServletRequest.class);
given(req.getAttribute(View.PATH_VARIABLES)).willReturn(null);
given(req.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)).willReturn(new AcceptHeaderLocaleResolver());
given(req.getLocale()).willReturn(Locale.CANADA);
final HttpServletResponse expectedResponse = new MockHttpServletResponse();
VelocityView vv = new VelocityView() {
@Override
protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception {
assertTrue(template == expectedTemplate);
assertTrue(response == expectedResponse);
assertEquals("myValue", context.get("myHelper"));
assertTrue(context.get("math") instanceof MathTool);
assertTrue(context.get("dateTool") instanceof DateTool);
DateTool dateTool = (DateTool) context.get("dateTool");
assertTrue(dateTool.getLocale().equals(Locale.CANADA));
assertTrue(context.get("numberTool") instanceof NumberTool);
NumberTool numberTool = (NumberTool) context.get("numberTool");
assertTrue(numberTool.getLocale().equals(Locale.CANADA));
}
@Override
protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
model.put("myHelper", "myValue");
}
};
vv.setUrl(templateName);
vv.setApplicationContext(wac);
Map<String, Class<?>> toolAttributes = new HashMap<String, Class<?>>();
toolAttributes.put("math", MathTool.class);
vv.setToolAttributes(toolAttributes);
vv.setDateToolAttribute("dateTool");
vv.setNumberToolAttribute("numberTool");
vv.setExposeSpringMacroHelpers(false);
vv.render(new HashMap<String, Object>(), req, expectedResponse);
assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, expectedResponse.getContentType());
}
示例11: testExposeHelpers
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
@Test
public void testExposeHelpers() throws Exception {
final String templateName = "test.vm";
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
final Template expectedTemplate = new Template();
VelocityConfig vc = new VelocityConfig() {
@Override
public VelocityEngine getVelocityEngine() {
return new TestVelocityEngine(templateName, expectedTemplate);
}
};
Map<String, VelocityConfig> configurers = new HashMap<String, VelocityConfig>();
configurers.put("velocityConfigurer", vc);
given(wac.getBeansOfType(VelocityConfig.class, true, false)).willReturn(configurers);
// let it ask for locale
HttpServletRequest req = mock(HttpServletRequest.class);
given(req.getAttribute(View.PATH_VARIABLES)).willReturn(null);
given(req.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)).willReturn(new AcceptHeaderLocaleResolver());
given(req.getLocale()).willReturn(Locale.CANADA);
final HttpServletResponse expectedResponse = new MockHttpServletResponse();
VelocityView vv = new VelocityView() {
@Override
protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception {
assertTrue(template == expectedTemplate);
assertTrue(response == expectedResponse);
assertEquals("myValue", context.get("myHelper"));
assertTrue(context.get("math") instanceof MathTool);
assertTrue(context.get("dateTool") instanceof DateTool);
DateTool dateTool = (DateTool) context.get("dateTool");
assertTrue(dateTool.getLocale().equals(Locale.CANADA));
assertTrue(context.get("numberTool") instanceof NumberTool);
NumberTool numberTool = (NumberTool) context.get("numberTool");
assertTrue(numberTool.getLocale().equals(Locale.CANADA));
}
@Override
protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
model.put("myHelper", "myValue");
}
};
vv.setUrl(templateName);
vv.setApplicationContext(wac);
Map<String, Class> toolAttributes = new HashMap<String, Class>();
toolAttributes.put("math", MathTool.class);
vv.setToolAttributes(toolAttributes);
vv.setDateToolAttribute("dateTool");
vv.setNumberToolAttribute("numberTool");
vv.setExposeSpringMacroHelpers(false);
vv.render(new HashMap<String, Object>(), req, expectedResponse);
assertEquals(AbstractView.DEFAULT_CONTENT_TYPE, expectedResponse.getContentType());
}
示例12: applyLifecycleMethods
import org.springframework.web.servlet.view.AbstractView; //導入依賴的package包/類
private View applyLifecycleMethods(String viewName, AbstractView view) {
return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, viewName);
}