Search in sources :

Example 11 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project spring-mvc-31-demo by rstoyanchev.

the class WebConfig method viewResolver.

@Bean
public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/views/");
    resolver.setSuffix(".jsp");
    return resolver;
}
Also used : InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) Bean(org.springframework.context.annotation.Bean)

Example 12 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project spring-framework by spring-projects.

the class DispatcherServletTests method withNoViewAndSamePath.

@Test
public void withNoViewAndSamePath() throws Exception {
    InternalResourceViewResolver vr = (InternalResourceViewResolver) complexDispatcherServlet.getWebApplicationContext().getBean("viewResolver2");
    vr.setSuffix("");
    MockServletContext servletContext = new MockServletContext();
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext, "GET", "/noview");
    MockHttpServletResponse response = new MockHttpServletResponse();
    try {
        complexDispatcherServlet.service(request, response);
        fail("Should have thrown ServletException");
    } catch (ServletException ex) {
        ex.printStackTrace();
    }
}
Also used : ServletException(javax.servlet.ServletException) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) MockServletContext(org.springframework.mock.web.test.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 13 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project spring-mvc-showcase by spring-projects.

the class FormControllerTests method setup.

@Before
public void setup() throws Exception {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/");
    viewResolver.setSuffix(".jsp");
    this.mockMvc = standaloneSetup(new FormController()).setViewResolvers(viewResolver).build();
}
Also used : InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) Before(org.junit.Before)

Example 14 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project spring-security-oauth by spring-projects.

the class WebMvcConfig method contentViewResolver.

@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
    ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/jsp/");
    viewResolver.setSuffix(".jsp");
    MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
    defaultView.setExtractValueFromSingleKeyModel(true);
    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setViewResolvers(Arrays.<ViewResolver>asList(viewResolver));
    contentViewResolver.setDefaultViews(Arrays.<View>asList(defaultView));
    return contentViewResolver;
}
Also used : ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) ContentNegotiatingViewResolver(org.springframework.web.servlet.view.ContentNegotiatingViewResolver) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView) InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 15 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project nikita-noark5-core by HiOA-ABI.

the class AppWebMvcConfiguration method getViewResolver.

/**
      * Used to set a suffix for the thymelaf templates under resources. All content will be under webapp
      * so we can use webapp as a suffix (even though I don't use it right now.)
      * Set a suffix (.html, .jsp etc) that all the files have to use.
      * The point of this is to make the (view) code generating html pages easier to read as we can ignore
      * prefixes and suffixes in code.
     */
@Bean
public ViewResolver getViewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    //resolver.setPrefix("webapp/");
    resolver.setSuffix(".html");
    return resolver;
}
Also used : InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) Bean(org.springframework.context.annotation.Bean)

Aggregations

InternalResourceViewResolver (org.springframework.web.servlet.view.InternalResourceViewResolver)15 Test (org.junit.Test)7 Bean (org.springframework.context.annotation.Bean)6 ContentNegotiationManagerFactoryBean (org.springframework.web.accept.ContentNegotiationManagerFactoryBean)2 ContentNegotiatingViewResolver (org.springframework.web.servlet.view.ContentNegotiatingViewResolver)2 MappingJackson2JsonView (org.springframework.web.servlet.view.json.MappingJackson2JsonView)2 ArrayList (java.util.ArrayList)1 ServletException (javax.servlet.ServletException)1 Before (org.junit.Before)1 ConversionServiceFactoryBean (org.springframework.context.support.ConversionServiceFactoryBean)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)1 MockServletContext (org.springframework.mock.web.test.MockServletContext)1 Jaxb2Marshaller (org.springframework.oxm.jaxb.Jaxb2Marshaller)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)1 FixedContentNegotiationStrategy (org.springframework.web.accept.FixedContentNegotiationStrategy)1 HeaderContentNegotiationStrategy (org.springframework.web.accept.HeaderContentNegotiationStrategy)1 View (org.springframework.web.servlet.View)1 ViewResolverComposite (org.springframework.web.servlet.view.ViewResolverComposite)1