|
| 1 | + |
1 | 2 | package application.configuration.jsf;
|
| 3 | + |
2 | 4 | import java.util.EnumSet;
|
3 | 5 | import java.util.HashMap;
|
4 | 6 |
|
5 |
| - |
6 | 7 | import javax.faces.webapp.FacesServlet;
|
7 | 8 | import javax.servlet.DispatcherType;
|
8 | 9 | import javax.servlet.ServletContext;
|
|
15 | 16 | import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
16 | 17 | import org.springframework.context.annotation.Bean;
|
17 | 18 | import org.springframework.context.annotation.Configuration;
|
| 19 | +import org.springframework.web.filter.DelegatingFilterProxy; |
18 | 20 |
|
19 | 21 | import com.sun.faces.config.ConfigureListener;
|
20 |
| -import org.springframework.web.filter.DelegatingFilterProxy; |
21 | 22 |
|
22 | 23 | /**
|
23 | 24 | * Created by anonymous on 1/31/16.
|
24 | 25 | */
|
25 | 26 | @Configuration
|
26 | 27 | public class JSFConfiguration {
|
27 |
| - /** |
28 |
| - * Configuración de ViewScope |
29 |
| - * |
30 |
| - * @return ViewScope |
31 |
| - */ |
32 |
| - @Bean |
33 |
| - public static ViewScope viewScope() { |
34 |
| - return new ViewScope(); |
35 |
| - } |
36 |
| - |
37 |
| - /** |
38 |
| - * Allows the use of @Scope("view") on Spring @Component, @Service and @Controller |
39 |
| - * beans |
40 |
| - */ |
41 |
| - @Bean |
42 |
| - public static CustomScopeConfigurer scopeConfigurer() { |
43 |
| - CustomScopeConfigurer configurer = new CustomScopeConfigurer(); |
44 |
| - HashMap<String, Object> hashMap = new HashMap<String, Object>(); |
45 |
| - hashMap.put("view", viewScope()); |
46 |
| - configurer.setScopes(hashMap); |
47 |
| - return configurer; |
48 |
| - } |
49 |
| - |
50 |
| - /* |
51 |
| - * Below sets up the Faces Servlet for Spring Boot |
52 |
| - */ |
53 |
| - @Bean |
54 |
| - public FacesServlet facesServlet() { |
55 |
| - return new FacesServlet(); |
56 |
| - } |
57 |
| - |
58 |
| - /** |
59 |
| - * Configuración de JSF |
60 |
| - * |
61 |
| - * @return |
62 |
| - */ |
63 |
| - @Bean |
64 |
| - public ServletRegistrationBean facesServletRegistration() { |
65 |
| - ServletRegistrationBean registration = new ServletRegistrationBean( |
66 |
| - facesServlet(), "*.xhtml"); |
67 |
| - registration.setName("FacesServlet"); |
68 |
| - registration.setLoadOnStartup(1); |
69 |
| - return registration; |
70 |
| - } |
71 |
| - |
72 |
| - /** |
73 |
| - * Configuración de JSF |
74 |
| - * |
75 |
| - * @return |
76 |
| - */ |
77 |
| - @Bean |
78 |
| - public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() { |
79 |
| - return new ServletListenerRegistrationBean<ConfigureListener>( |
80 |
| - new ConfigureListener()); |
81 |
| - } |
82 |
| - |
83 |
| - /** |
84 |
| - * Configuración de servlet startup de JSF |
85 |
| - * |
86 |
| - * @return |
87 |
| - */ |
88 |
| - @Bean |
89 |
| - public ServletContextInitializer initializer() { |
90 |
| - return new ServletContextInitializer() { |
91 |
| - |
92 |
| - @Override |
93 |
| - public void onStartup(ServletContext servletContext) |
94 |
| - throws ServletException { |
95 |
| - |
96 |
| - //Los parámetros del servlet (web.xml) son agregados aquí |
97 |
| - //De todas formas se debe de dejar el archivo web.xml para que no arroje errores JSF |
98 |
| - |
99 |
| - //Asignamos el tema de Bootstrap |
100 |
| - servletContext.setInitParameter("primefaces.THEME", |
101 |
| - "bootstrap"); |
102 |
| - servletContext.setInitParameter("javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL","true"); |
103 |
| - |
104 |
| - //Configuración de taglibs con Spring Security |
105 |
| - servletContext.setInitParameter( |
106 |
| - "com.sun.faces.forceLoadConfiguration", "true"); |
107 |
| - servletContext.setInitParameter( |
108 |
| - "javax.faces.FACELETS_LIBRARIES", |
109 |
| - "/WEB-INF/springsecurity.taglib.xml"); |
110 |
| - servletContext.setInitParameter("javax.faces.FACELETS_LIBRARIES", "/WEB-INF/springsecurity.taglib.xml"); |
111 |
| - |
112 |
| - EnumSet<DispatcherType> tiposDispatcher = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); |
113 |
| - servletContext.addFilter("securityFilter", |
114 |
| - new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(tiposDispatcher, false, "/*"); |
115 |
| - |
116 |
| - //Configuración del filter upload de Primefaces |
117 |
| - servletContext.setInitParameter("primefaces.UPLOADER", "commons"); |
118 |
| - servletContext.addFilter("PrimeFaces FileUpload Filter", new FileUploadFilter()) |
119 |
| - .addMappingForServletNames(tiposDispatcher, false, "FacesServlet"); |
120 |
| - |
121 |
| - //ViewExpiredException filter register |
122 |
| - servletContext.addFilter("errorHandlerFilter", new ViewExpiredExceptionFilter()) |
123 |
| - .addMappingForUrlPatterns(tiposDispatcher,false, "/*"); |
124 |
| - |
125 |
| - } |
126 |
| - }; |
127 |
| - } |
| 28 | + /** |
| 29 | + * Configuración de ViewScope |
| 30 | + * |
| 31 | + * @return ViewScope |
| 32 | + */ |
| 33 | + @Bean |
| 34 | + public static ViewScope viewScope() { |
| 35 | + return new ViewScope(); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Allows the use of @Scope("view") on Spring @Component, @Service and @Controller |
| 40 | + * beans |
| 41 | + */ |
| 42 | + @Bean |
| 43 | + public static CustomScopeConfigurer scopeConfigurer() { |
| 44 | + CustomScopeConfigurer configurer = new CustomScopeConfigurer(); |
| 45 | + HashMap<String, Object> hashMap = new HashMap<String, Object>(); |
| 46 | + hashMap.put("view", viewScope()); |
| 47 | + configurer.setScopes(hashMap); |
| 48 | + return configurer; |
| 49 | + } |
| 50 | + |
| 51 | + /* |
| 52 | + * Below sets up the Faces Servlet for Spring Boot |
| 53 | + */ |
| 54 | + @Bean |
| 55 | + public FacesServlet facesServlet() { |
| 56 | + return new FacesServlet(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Configuración de JSF |
| 61 | + * |
| 62 | + * @return |
| 63 | + */ |
| 64 | + @Bean |
| 65 | + public ServletRegistrationBean facesServletRegistration() { |
| 66 | + ServletRegistrationBean registration = new ServletRegistrationBean( |
| 67 | + facesServlet(), "*.xhtml"); |
| 68 | + registration.setName("FacesServlet"); |
| 69 | + registration.setLoadOnStartup(1); |
| 70 | + return registration; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Configuración de JSF |
| 75 | + * |
| 76 | + * @return |
| 77 | + */ |
| 78 | + @Bean |
| 79 | + public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() { |
| 80 | + return new ServletListenerRegistrationBean<ConfigureListener>( |
| 81 | + new ConfigureListener()); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Configuración de servlet startup de JSF |
| 86 | + * |
| 87 | + * @return |
| 88 | + */ |
| 89 | + @Bean |
| 90 | + public ServletContextInitializer initializer() { |
| 91 | + return new ServletContextInitializer() { |
| 92 | + |
| 93 | + @Override |
| 94 | + public void onStartup(ServletContext servletContext) |
| 95 | + throws ServletException { |
| 96 | + |
| 97 | + // Los parámetros del servlet (web.xml) son agregados aquí |
| 98 | + // De todas formas se debe de dejar el archivo web.xml para que no arroje errores JSF |
| 99 | + |
| 100 | + servletContext.setInitParameter("javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL", "true"); |
| 101 | + |
| 102 | + // Configuración de taglibs con Spring Security |
| 103 | + servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", "true"); |
| 104 | + servletContext.setInitParameter("javax.faces.FACELETS_LIBRARIES", "/WEB-INF/springsecurity.taglib.xml"); |
| 105 | + |
| 106 | + EnumSet<DispatcherType> tiposDispatcher = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); |
| 107 | + servletContext.addFilter("securityFilter", |
| 108 | + new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(tiposDispatcher, false, "/*"); |
| 109 | + |
| 110 | + // Configuración del filter upload de Primefaces |
| 111 | + servletContext.setInitParameter("primefaces.UPLOADER", "commons"); |
| 112 | + servletContext.addFilter("PrimeFaces FileUpload Filter", new FileUploadFilter()) |
| 113 | + .addMappingForServletNames(tiposDispatcher, false, "FacesServlet"); |
| 114 | + |
| 115 | + // ViewExpiredException filter register |
| 116 | + servletContext.addFilter("errorHandlerFilter", new ViewExpiredExceptionFilter()) |
| 117 | + .addMappingForUrlPatterns(tiposDispatcher, false, "/*"); |
| 118 | + |
| 119 | + } |
| 120 | + }; |
| 121 | + } |
128 | 122 | }
|
0 commit comments