javax.faces.webapp.FacesServlet Java Examples
The following examples show how to use
javax.faces.webapp.FacesServlet.
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: FacesServletAutoConfiguration.java From joinfaces with Apache License 2.0 | 6 votes |
/** * This bean registers the {@link FacesServlet}. * <p> * This {@link ServletRegistrationBean} also sets two * {@link ServletContext#setAttribute(String, Object) servlet-context attributes} to inform Mojarra and MyFaces about * the dynamically added Servlet. * * @param facesServletProperties The properties for the {@link FacesServlet}-registration. * * @return A custom {@link ServletRegistrationBean} which registers the {@link FacesServlet}. */ @Bean public ServletRegistrationBean<FacesServlet> facesServletRegistrationBean( FacesServletProperties facesServletProperties ) { ServletRegistrationBean<FacesServlet> facesServletServletRegistrationBean = new ServletRegistrationBean<FacesServlet>(new FacesServlet()) { @Override protected ServletRegistration.Dynamic addRegistration(String description, ServletContext servletContext) { ServletRegistration.Dynamic servletRegistration = super.addRegistration(description, servletContext); if (servletRegistration != null) { servletContext.setAttribute("org.apache.myfaces.DYNAMICALLY_ADDED_FACES_SERVLET", true); servletContext.setAttribute("com.sun.faces.facesInitializerMappingsAdded", true); } return servletRegistration; } }; facesServletServletRegistrationBean.setName(facesServletProperties.getName()); facesServletServletRegistrationBean.setUrlMappings(facesServletProperties.getUrlMappings()); facesServletServletRegistrationBean.setLoadOnStartup(facesServletProperties.getLoadOnStartup()); facesServletServletRegistrationBean.setEnabled(facesServletProperties.isEnabled()); facesServletServletRegistrationBean.setAsyncSupported(facesServletProperties.isAsyncSupported()); facesServletServletRegistrationBean.setOrder(facesServletProperties.getOrder()); return facesServletServletRegistrationBean; }
Example #2
Source File: JSFs.java From tomee with Apache License 2.0 | 6 votes |
public static WebArchive base(final String name) { final String webXml = Descriptors.create(WebAppDescriptor.class) .version("3.0") .createServlet() .servletName("jsf") .servletClass(FacesServlet.class.getName()) .loadOnStartup(1) .up() .createServletMapping() .servletName("jsf") .urlPattern("*.xhtml") // not the default .up() .exportAsString(); return ShrinkWrap.create(WebArchive.class, name) .setWebXML(new StringAsset(webXml)); }
Example #3
Source File: JMSInjectionTest.java From tomee with Apache License 2.0 | 6 votes |
@Deployment(testable = false) public static WebArchive getArchive() { return ShrinkWrap.create(WebArchive.class, "jsf-jms-test.war") .addClasses(DummyManagedBean.class) .addAsWebResource(new ClassLoaderAsset( JMSInjectionTest.class.getPackage().getName().replace('.', '/').concat("/").concat("dummy.xhtml")), "dummy.xhtml") .setWebXML(new StringAsset(Descriptors.create(WebAppDescriptor.class) .version("3.0") .createServlet() .servletName("jsf") .servletClass(FacesServlet.class.getName()) .loadOnStartup(1) .up() .createServletMapping() .servletName("jsf") .urlPattern("*.xhtml") // not the default .up() .exportAsString())); }
Example #4
Source File: FacesServletAutoConfigurationTest.java From joinfaces with Apache License 2.0 | 5 votes |
@Test public void testDefaultMapping() { this.webApplicationContextRunner .run(context -> { ServletRegistrationBean<FacesServlet> facesServletRegistrationBean = (ServletRegistrationBean<FacesServlet>) context.getBean("facesServletRegistrationBean"); assertThat(facesServletRegistrationBean.getUrlMappings()).containsExactlyInAnyOrder("/faces/*", "*.jsf", "*.faces", "*.xhtml"); }); }
Example #5
Source File: FacesServletAutoConfigurationTest.java From joinfaces with Apache License 2.0 | 5 votes |
@Test public void testCustomMapping() { this.webApplicationContextRunner .withPropertyValues("joinfaces.faces-servlet.url-mappings=foo,bar") .run(context -> { ServletRegistrationBean<FacesServlet> facesServletRegistrationBean = (ServletRegistrationBean<FacesServlet>) context.getBean("facesServletRegistrationBean"); assertThat(facesServletRegistrationBean.getUrlMappings()).containsExactlyInAnyOrder("foo", "bar"); }); }
Example #6
Source File: FacesServletAutoConfigurationTest.java From joinfaces with Apache License 2.0 | 5 votes |
@Test public void testDisableFacesservletToXhtmlDefaultMapping_false() { this.webApplicationContextRunner .withPropertyValues("joinfaces.jsf.disable-facesservlet-to-xhtml=false") .run(context -> { ServletRegistrationBean<FacesServlet> facesServletRegistrationBean = (ServletRegistrationBean<FacesServlet>) context.getBean("facesServletRegistrationBean"); assertThat(facesServletRegistrationBean.getUrlMappings()).containsExactlyInAnyOrder("/faces/*", "*.jsf", "*.faces", "*.xhtml"); }); }
Example #7
Source File: FacesServletAutoConfigurationTest.java From joinfaces with Apache License 2.0 | 5 votes |
@Test public void testDisableFacesservletToXhtmlDefaultMapping_true() { this.webApplicationContextRunner .withPropertyValues("joinfaces.jsf.disable-facesservlet-to-xhtml=true") .run(context -> { ServletRegistrationBean<FacesServlet> facesServletRegistrationBean = (ServletRegistrationBean<FacesServlet>) context.getBean("facesServletRegistrationBean"); assertThat(facesServletRegistrationBean.getUrlMappings()).containsExactlyInAnyOrder("/faces/*", "*.jsf", "*.faces"); }); }
Example #8
Source File: FacesServletAutoConfigurationTest.java From joinfaces with Apache License 2.0 | 5 votes |
@Test public void testDisableFacesservletToXhtmlCustomMapping() { this.webApplicationContextRunner .withPropertyValues("joinfaces.jsf.disable-facesservlet-to-xhtml=true", "joinfaces.faces-servlet.url-mappings=*.xhtml") .run(context -> { ServletRegistrationBean<FacesServlet> facesServletRegistrationBean = (ServletRegistrationBean<FacesServlet>) context.getBean("facesServletRegistrationBean"); assertThat(facesServletRegistrationBean.getUrlMappings()).containsExactly("*.xhtml"); }); }
Example #9
Source File: FacesServletAutoConfigurationTest.java From joinfaces with Apache License 2.0 | 5 votes |
@Test public void testServletContextAttributes_added() { this.webApplicationContextRunner .run(context -> { ServletRegistrationBean<FacesServlet> facesServletRegistrationBean = (ServletRegistrationBean<FacesServlet>) context.getBean("facesServletRegistrationBean"); ServletContext servletContext = mock(ServletContext.class); when(servletContext.addServlet(anyString(), any(Servlet.class))).thenReturn(mock(ServletRegistration.Dynamic.class)); facesServletRegistrationBean.onStartup(servletContext); verify(servletContext, times(2)).setAttribute(any(), any()); }); }
Example #10
Source File: FacesServletAutoConfigurationTest.java From joinfaces with Apache License 2.0 | 5 votes |
@Test public void testServletContextAttributes_notAdded() { this.webApplicationContextRunner .run(context -> { ServletRegistrationBean<FacesServlet> facesServletRegistrationBean = (ServletRegistrationBean<FacesServlet>) context.getBean("facesServletRegistrationBean"); ServletContext servletContext = mock(ServletContext.class); when(servletContext.addServlet(anyString(), any(Servlet.class))).thenReturn(null); facesServletRegistrationBean.onStartup(servletContext); verify(servletContext, times(0)).setAttribute(any(), any()); }); }
Example #11
Source File: TomEEMyFacesContainerInitializer.java From tomee with Apache License 2.0 | 5 votes |
private boolean isFacesConfigPresent(final ServletContext servletContext) { try { if (servletContext.getResource("/WEB-INF/faces-config.xml") != null) { return true; } final String configFilesAttrValue = servletContext.getInitParameter(FacesServlet.CONFIG_FILES_ATTR); if (configFilesAttrValue != null) { final String[] configFiles = configFilesAttrValue.split(","); for (final String file : configFiles) { if (servletContext.getResource(file.trim()) != null) { return true; } } } final Collection<URL> metaInfFacesConfigUrls = new TomEEFacesConfigResourceProvider().getMetaInfConfigurationResources(null); if (metaInfFacesConfigUrls == null) { return false; } // remove our internal faces-config.xml final Iterator<URL> it = metaInfFacesConfigUrls.iterator(); while (it.hasNext()) { final URL next = it.next(); if (isOwb(next)) { it.remove(); } } return !metaInfFacesConfigUrls.isEmpty(); } catch (final Exception e) { return false; } }
Example #12
Source File: Main.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 4 votes |
@Bean public ServletRegistrationBean servletRegistrationBean() { FacesServlet servlet = new FacesServlet(); return new ServletRegistrationBean(servlet, "*.xhtml"); }
Example #13
Source File: FenixFacesServlet.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 4 votes |
public FenixFacesServlet() { super(); facesServlet = new FacesServlet(); }