How to run a JSF 2.2 page in Java EE 7 without web.xml?

What is wrong with my very simple web application: the web application was successfully deployed on the application server, but hi bean did not enter index.xhtml on the page (the page shows only Hello from Facelets: # {hello.value})?

(this is the first time I work with JSF, so maybe this question is very simple, and I also used a good article http://arjan-tijms.omnifaces.org/2011/08/minimal-3-tier-java- ee-app-without-any.html )

I have the following military archive structure:

mywebapp | - WEB_INF | - classes | - Hello.class - index.html 

Hello.java has:

 import javax.enterprise.context.RequestScoped; import javax.inject.Named; @Named @RequestScoped public class Hello { private String value; public String getValue() { return "Hello JSF"; } public void setValue(String value) { this.value = value; } } 

as well as my index.xhtml

 <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"> <h:head> <title>My Facelet Page Title</title> </h:head> <h:body> Hello from Facelets: #{hello.value} </h:body> </html> 

For the construction project, I used pom.xml:

 .... <packaging>war</packaging> <name>Simple web app</name> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency> </dependencies> 
+5
source share
2 answers

Adapted from JavaServerFaces 2.0, The Complete Reference :

An entry in the web.xml file of web applications includes the Faces Controller servlet when a specific URL pattern is defined, for example / faces /. When running JSF 2.0 on a Servlet 3.0 container such as Suns Glassfish v3, web.xml is optional. If no web.xml is detected, the Faces Controller servlet automatically displays the most popular URL patterns: / faces / ,. jsf and .faces.

So you should try something like this:

localhost:8080/mywebapp/faces/index.xhtml .

+4
source

According to javadoc , FacesServlet will be automatically registered if one of the following conditions is FacesServlet :

  • The faces-config.xml file is located in WEB-INF
  • The faces-config.xml file is located in the META-INF jar META-INF in the application class path.
  • A file name ending in .faces-config.xml is located in the META-INF jar META-INF in the application class path.
  • The javax.faces.CONFIG_FILES context javax.faces.CONFIG_FILES declared in web.xml or web-fragment.xml .
  • Set classes passed to the onStartup() ServletContainerInitializer implementation is not empty.

If you use web.xml only for registering FacesServlet , then this will not be necessary if any of the above conditions is met.

+5
source

Source: https://habr.com/ru/post/1202537/


All Articles