JSF 2 with HTML pages instead of XHTML

I am trying to configure JSF to use html files.

If I use the .xhtml template ( <url-pattern>*.xhtml</url-pattern> ) and name my files with the extension xhtml, the pages load correctly and are parsed.

However, if I change this to <url-pattern>*.html</url-pattern> .html <url-pattern>*.html</url-pattern> and name the files the extension .html, I get 500 errors:

 The server encountered an internal error () that prevented it from fulfilling this request. Exception: java.lang.NullPointerException 

Server Logs:

 WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception java.lang.NullPointerException at com.sun.faces.context.flash.ELFlash.getPhaseMapForReading(ELFlash.java:748) at com.sun.faces.context.flash.ELFlash.isEmpty(ELFlash.java:466) at com.sun.faces.facelets.util.DevTools.writeVariables(DevTools.java:318) at com.sun.faces.facelets.util.DevTools.writeVariables(DevTools.java:208) at com.sun.faces.facelets.util.DevTools.debugHtml(DevTools.java:123) at com.sun.faces.renderkit.RenderKitUtils.renderHtmlErrorPage(RenderKitUtils.java:1139) at com.sun.faces.context.ExceptionHandlerImpl.throwIt(ExceptionHandlerImpl.java:249) at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:136) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:680) 

Here is my web.xml file:

 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>com.test.cms</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> </web-app> 
+4
source share
2 answers

However, if I change this to * .html and name the files the extension .html , I get 500 errors

Did you mean that you renamed the physical .xhtml files to .html ? You do not need to do this. Rename them back to .xhtml and continue to use .html in the urls. FacesServlet will automatically load the right XHTML file associated with the URL.

If you really need to provide the .html extension, you will also need to change the default suffix to .html . Add the following entry to web.xml to achieve this:

 <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.html</param-value> </context-param> 

See also:

+8
source

As BalusC said, you do not need to change the names of physical files.

But anyway, I noticed odd values ​​in your web.xml schema. There are mixed values ​​for versions 2_5 and 3_0.

In the settings below, you should be able to store files with the extension .xhtml and access them as .html .

 <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app> 

I tested it in GlassFish 3.1.2 using Mojarra 2.1.6 and it works great.

Hope this helps.

+3
source

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


All Articles