org.springframework.web.servlet.mvc.ParameterizableViewController Java Examples
The following examples show how to use
org.springframework.web.servlet.mvc.ParameterizableViewController.
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: MvcNamespaceTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testViewControllersDefaultConfig() { loadBeanDefinitions("mvc-config-view-controllers-minimal.xml", 7); SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(hm); ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path"); assertNotNull(viewController); assertEquals("home", viewController.getViewName()); ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old"); assertNotNull(redirectViewController); assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class)); ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad"); assertNotNull(statusViewController); assertEquals(404, statusViewController.getStatusCode().value()); BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class); assertNotNull(beanNameMapping); assertEquals(2, beanNameMapping.getOrder()); }
Example #2
Source File: MvcNamespaceTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testViewControllersDefaultConfig() { loadBeanDefinitions("mvc-config-view-controllers-minimal.xml"); SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(hm); ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path"); assertNotNull(viewController); assertEquals("home", viewController.getViewName()); ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old"); assertNotNull(redirectViewController); assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class)); ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad"); assertNotNull(statusViewController); assertEquals(404, statusViewController.getStatusCode().value()); BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class); assertNotNull(beanNameMapping); assertEquals(2, beanNameMapping.getOrder()); }
Example #3
Source File: MvcNamespaceTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testViewControllersDefaultConfig() { loadBeanDefinitions("mvc-config-view-controllers-minimal.xml"); SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(hm); ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path"); assertNotNull(viewController); assertEquals("home", viewController.getViewName()); ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old"); assertNotNull(redirectViewController); assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class)); ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad"); assertNotNull(statusViewController); assertEquals(404, statusViewController.getStatusCode().value()); BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class); assertNotNull(beanNameMapping); assertEquals(2, beanNameMapping.getOrder()); }
Example #4
Source File: WelcomePageHandlerMapping.java From haven-platform with Apache License 2.0 | 5 votes |
WelcomePageHandlerMapping(Collection<String> paths) { ParameterizableViewController controller = new ParameterizableViewController(); controller.setViewName("forward:" + target); paths.forEach(path -> registerHandler(path, controller)); //we handle only non handled resources, but resource handler (which has LOWEST_PRECEDENCE - 1) handle all setOrder(LOWEST_PRECEDENCE - 10); }
Example #5
Source File: ViewControllerRegistryTests.java From java-technology-stack with MIT License | 5 votes |
private RedirectView getRedirectView(String path) { ParameterizableViewController controller = getController(path); assertNull(controller.getViewName()); assertNotNull(controller.getView()); assertEquals(RedirectView.class, controller.getView().getClass()); return (RedirectView) controller.getView(); }
Example #6
Source File: ViewControllerRegistryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void addStatusController() { this.registry.addStatusController("/path", HttpStatus.NOT_FOUND); ParameterizableViewController controller = getController("/path"); assertNull(controller.getViewName()); assertEquals(HttpStatus.NOT_FOUND, controller.getStatusCode()); assertTrue(controller.isStatusOnly()); assertNotNull(controller.getApplicationContext()); }
Example #7
Source File: ViewControllerRegistryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void addViewControllerWithDefaultViewName() { this.registry.addViewController("/path"); ParameterizableViewController controller = getController("/path"); assertNull(controller.getViewName()); assertNull(controller.getStatusCode()); assertFalse(controller.isStatusOnly()); assertNotNull(controller.getApplicationContext()); }
Example #8
Source File: ViewControllerRegistryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void addViewController() { this.registry.addViewController("/path").setViewName("viewName"); ParameterizableViewController controller = getController("/path"); assertEquals("viewName", controller.getViewName()); assertNull(controller.getStatusCode()); assertFalse(controller.isStatusOnly()); assertNotNull(controller.getApplicationContext()); }
Example #9
Source File: ViewControllerRegistryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void addViewController() { this.registry.addViewController("/path").setViewName("viewName"); ParameterizableViewController controller = getController("/path"); assertEquals("viewName", controller.getViewName()); assertNull(controller.getStatusCode()); assertFalse(controller.isStatusOnly()); assertNotNull(controller.getApplicationContext()); }
Example #10
Source File: ViewControllerRegistryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void addViewControllerWithDefaultViewName() { this.registry.addViewController("/path"); ParameterizableViewController controller = getController("/path"); assertNull(controller.getViewName()); assertNull(controller.getStatusCode()); assertFalse(controller.isStatusOnly()); assertNotNull(controller.getApplicationContext()); }
Example #11
Source File: ViewControllerRegistryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void addStatusController() { this.registry.addStatusController("/path", HttpStatus.NOT_FOUND); ParameterizableViewController controller = getController("/path"); assertNull(controller.getViewName()); assertEquals(HttpStatus.NOT_FOUND, controller.getStatusCode()); assertTrue(controller.isStatusOnly()); assertNotNull(controller.getApplicationContext()); }
Example #12
Source File: ViewControllerRegistryTests.java From spring-analysis-note with MIT License | 5 votes |
private RedirectView getRedirectView(String path) { ParameterizableViewController controller = getController(path); assertNull(controller.getViewName()); assertNotNull(controller.getView()); assertEquals(RedirectView.class, controller.getView().getClass()); return (RedirectView) controller.getView(); }
Example #13
Source File: ViewControllerRegistryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void addStatusController() { this.registry.addStatusController("/path", HttpStatus.NOT_FOUND); ParameterizableViewController controller = getController("/path"); assertNull(controller.getViewName()); assertEquals(HttpStatus.NOT_FOUND, controller.getStatusCode()); assertTrue(controller.isStatusOnly()); assertNotNull(controller.getApplicationContext()); }
Example #14
Source File: ViewControllerRegistryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void addViewControllerWithDefaultViewName() { this.registry.addViewController("/path"); ParameterizableViewController controller = getController("/path"); assertNull(controller.getViewName()); assertNull(controller.getStatusCode()); assertFalse(controller.isStatusOnly()); assertNotNull(controller.getApplicationContext()); }
Example #15
Source File: ViewControllerRegistryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void addViewController() { this.registry.addViewController("/path").setViewName("viewName"); ParameterizableViewController controller = getController("/path"); assertEquals("viewName", controller.getViewName()); assertNull(controller.getStatusCode()); assertFalse(controller.isStatusOnly()); assertNotNull(controller.getApplicationContext()); }
Example #16
Source File: ViewControllerRegistryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private RedirectView getRedirectView(String path) { ParameterizableViewController controller = getController(path); assertNull(controller.getViewName()); assertNotNull(controller.getView()); assertEquals(RedirectView.class, controller.getView().getClass()); return (RedirectView) controller.getView(); }
Example #17
Source File: ViewControllerRegistryTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
private ParameterizableViewController getController(String path) { Map<String, ?> urlMap = getHandlerMapping().getUrlMap(); ParameterizableViewController controller = (ParameterizableViewController) urlMap.get(path); assertNotNull(controller); return controller; }
Example #18
Source File: ViewControllerRegistryTests.java From java-technology-stack with MIT License | 4 votes |
private ParameterizableViewController getController(String path) { Map<String, ?> urlMap = this.registry.buildHandlerMapping().getUrlMap(); ParameterizableViewController controller = (ParameterizableViewController) urlMap.get(path); assertNotNull(controller); return controller; }
Example #19
Source File: ParameterizableViewControllerTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { this.controller = new ParameterizableViewController(); this.request = new MockHttpServletRequest("GET", "/"); this.response = new MockHttpServletResponse(); }
Example #20
Source File: ViewControllerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register SimpleUrlHandlerMapping for view controllers BeanDefinition hm = registerHandlerMapping(parserContext, source); // Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off" MvcNamespaceUtils.registerDefaultComponents(parserContext, source); // Create view controller bean definition RootBeanDefinition controller = new RootBeanDefinition(ParameterizableViewController.class); controller.setSource(source); HttpStatus statusCode = null; if (element.hasAttribute("status-code")) { int statusValue = Integer.valueOf(element.getAttribute("status-code")); statusCode = HttpStatus.valueOf(statusValue); } String name = element.getLocalName(); if (name.equals("view-controller")) { if (element.hasAttribute("view-name")) { controller.getPropertyValues().add("viewName", element.getAttribute("view-name")); } if (statusCode != null) { controller.getPropertyValues().add("statusCode", statusCode); } } else if (name.equals("redirect-view-controller")) { controller.getPropertyValues().add("view", getRedirectView(element, statusCode, source)); } else if (name.equals("status-controller")) { controller.getPropertyValues().add("statusCode", statusCode); controller.getPropertyValues().add("statusOnly", true); } else { // Should never happen... throw new IllegalStateException("Unexpected tag name: " + name); } Map<String, BeanDefinition> urlMap; if (hm.getPropertyValues().contains("urlMap")) { urlMap = (Map<String, BeanDefinition>) hm.getPropertyValues().getPropertyValue("urlMap").getValue(); } else { urlMap = new ManagedMap<String, BeanDefinition>(); hm.getPropertyValues().add("urlMap", urlMap); } urlMap.put(element.getAttribute("path"), controller); return null; }
Example #21
Source File: RedirectViewControllerRegistration.java From spring4-understanding with Apache License 2.0 | 4 votes |
protected ParameterizableViewController getViewController() { return this.controller; }
Example #22
Source File: ViewControllerRegistration.java From spring4-understanding with Apache License 2.0 | 4 votes |
protected ParameterizableViewController getViewController() { return this.controller; }
Example #23
Source File: ViewControllerBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register SimpleUrlHandlerMapping for view controllers BeanDefinition hm = registerHandlerMapping(parserContext, source); // Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off" MvcNamespaceUtils.registerDefaultComponents(parserContext, source); // Create view controller bean definition RootBeanDefinition controller = new RootBeanDefinition(ParameterizableViewController.class); controller.setSource(source); HttpStatus statusCode = null; if (element.hasAttribute("status-code")) { int statusValue = Integer.valueOf(element.getAttribute("status-code")); statusCode = HttpStatus.valueOf(statusValue); } String name = element.getLocalName(); if (name.equals("view-controller")) { if (element.hasAttribute("view-name")) { controller.getPropertyValues().add("viewName", element.getAttribute("view-name")); } if (statusCode != null) { controller.getPropertyValues().add("statusCode", statusCode); } } else if (name.equals("redirect-view-controller")) { controller.getPropertyValues().add("view", getRedirectView(element, statusCode, source)); } else if (name.equals("status-controller")) { controller.getPropertyValues().add("statusCode", statusCode); controller.getPropertyValues().add("statusOnly", true); } else { // Should never happen... throw new IllegalStateException("Unexpected tag name: " + name); } Map<String, BeanDefinition> urlMap; if (hm.getPropertyValues().contains("urlMap")) { urlMap = (Map<String, BeanDefinition>) hm.getPropertyValues().getPropertyValue("urlMap").getValue(); } else { urlMap = new ManagedMap<String, BeanDefinition>(); hm.getPropertyValues().add("urlMap", urlMap); } urlMap.put(element.getAttribute("path"), controller); return null; }
Example #24
Source File: RedirectViewControllerRegistration.java From lams with GNU General Public License v2.0 | 4 votes |
protected ParameterizableViewController getViewController() { return this.controller; }
Example #25
Source File: ViewControllerRegistration.java From lams with GNU General Public License v2.0 | 4 votes |
protected ParameterizableViewController getViewController() { return this.controller; }
Example #26
Source File: ViewControllerRegistration.java From spring-analysis-note with MIT License | 4 votes |
protected ParameterizableViewController getViewController() { return this.controller; }
Example #27
Source File: ViewControllerBeanDefinitionParser.java From java-technology-stack with MIT License | 4 votes |
@Override @SuppressWarnings("unchecked") public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register SimpleUrlHandlerMapping for view controllers BeanDefinition hm = registerHandlerMapping(parserContext, source); // Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off" MvcNamespaceUtils.registerDefaultComponents(parserContext, source); // Create view controller bean definition RootBeanDefinition controller = new RootBeanDefinition(ParameterizableViewController.class); controller.setSource(source); HttpStatus statusCode = null; if (element.hasAttribute("status-code")) { int statusValue = Integer.parseInt(element.getAttribute("status-code")); statusCode = HttpStatus.valueOf(statusValue); } String name = element.getLocalName(); if (name.equals("view-controller")) { if (element.hasAttribute("view-name")) { controller.getPropertyValues().add("viewName", element.getAttribute("view-name")); } if (statusCode != null) { controller.getPropertyValues().add("statusCode", statusCode); } } else if (name.equals("redirect-view-controller")) { controller.getPropertyValues().add("view", getRedirectView(element, statusCode, source)); } else if (name.equals("status-controller")) { controller.getPropertyValues().add("statusCode", statusCode); controller.getPropertyValues().add("statusOnly", true); } else { // Should never happen... throw new IllegalStateException("Unexpected tag name: " + name); } Map<String, BeanDefinition> urlMap = (Map<String, BeanDefinition>) hm.getPropertyValues().get("urlMap"); if (urlMap == null) { urlMap = new ManagedMap<>(); hm.getPropertyValues().add("urlMap", urlMap); } urlMap.put(element.getAttribute("path"), controller); return null; }
Example #28
Source File: RedirectViewControllerRegistration.java From java-technology-stack with MIT License | 4 votes |
protected ParameterizableViewController getViewController() { return this.controller; }
Example #29
Source File: ViewControllerRegistration.java From java-technology-stack with MIT License | 4 votes |
protected ParameterizableViewController getViewController() { return this.controller; }
Example #30
Source File: ViewControllerRegistryTests.java From spring-analysis-note with MIT License | 4 votes |
private ParameterizableViewController getController(String path) { Map<String, ?> urlMap = this.registry.buildHandlerMapping().getUrlMap(); ParameterizableViewController controller = (ParameterizableViewController) urlMap.get(path); assertNotNull(controller); return controller; }