I searched for a solution but could not find an answer for my specific issue. I have a login.xhtml page but the JSF tags are not rendered. When I successfully log in, the tags are renderen correctly. so somehow the login.xhtml does not pass through the faces servlet. This seems strange because all is configured correctly. How can I force the login.xhtml to be rendered correctly?
Here is my web.xml portion
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/error.xhtml</form-error-page>
</form-login-config>
</login-config>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Login.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/templates/eps_template.xhtml">
<ui:define name="body">
<h2>Hello, please log in:</h2>
<form name="loginForm" method="post" action="j_security_check">
<p>
<strong><label for="username">Please type your user
name: </label> </strong> <input id="username" type="text" name="j_username"
size="25" />
</p>
<p>
<strong><label for="password">Please type your
password: </label> </strong> <input id="password" type="password" size="15"
name="j_password" />
</p>
<p>
<input type="submit" value="Submit" /> <input type="reset"
value="Reset" />
</p>
</form>
</ui:define>
</ui:composition>
So the html form is shown correctly, but the template components are not. The output is:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/templates/eps_template.xhtml">
<ui:define name="body">
<h2>Hello, please log in:</h2>
<form name="loginForm" method="post" action="j_security_check">
<p>
<strong><label for="username">Please type your user
name: </label> </strong> <input id="username" type="text" name="j_username"
size="25" />
</p>
<p>
<strong><label for="password">Please type your
password: </label> </strong> <input id="password" type="password" size="15"
name="j_password" />
</p>
<p>
<input type="submit" value="Submit" /> <input type="reset"
value="Reset" />
</p>
</form>
</ui:define>
</ui:composition>
Update 31 January 2012
Configuration:
Glassfish 3.1
Primefaces 3.1
JSF 2.1
I have a index.html page which forwards to home.jsf. But the container notices the user is not logged in so it redirects to login.xhtml.
If I add only the *.jsf to the web.xml, all is working fine but the login.jsf does not render JSF tags.
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
If I also add *.xhtml the login.jsf page does render tags but not properly according to the Primefaces skin. When I click submit the jquery.js is printed to the screen.
Here is the complete web.xml
<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>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<!-- Primefaces -->
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bluesky</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>5120</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/****</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<!-- security -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/error.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>epsadmin</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<display-name>Restrict raw XHTML documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
Update after answer 2 by BalusC. This is now the complete web.xml
<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>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bluesky</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>5120</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/tempupload</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<welcome-file-list>
<welcome-file>home.jsf</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/login.jsf</form-login-page>
<form-error-page>/error.jsf</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin</web-resource-name>
<url-pattern>*.jsf</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<error-page>
<error-code>403</error-code>
<location>/errorpages/error403.jsf</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/errorpages/error404.jsf</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/errorpages/error500.jsf</location>
</error-page>
<error-page>
<exception-type>com.*******.ApplicationException</exception-type>
<location>/errorpages/error500.jsf</location>
</error-page>
This is the url I get when pressing the submit button
csman/javax.faces.resource/primefaces.js.jsf?ln=primefaces&v=3.1-SNAPSHOT
This is the output.
PrimeFaces={escapeClientId:function(a){return"#"+a ..........etc
However, when I press connect to the start URL again, I am successfully directed to the home.jsf page. So the login procedure went OK.
Not that the login.jsf page displays JSF tags but they are not skinned.
Weird?!
You have configured your
FacesServletto listen on*.jsfURLs. So all you need to do is to change the login and error pages to point to exactly that URL.So, change
to
Don’t forget to remove the additional
*.xhtmlURL pattern on theFacesServletas suggested by the other answer. You have a<security-constraint>on*.xhtmlto block the endusers seeing the raw source and this won’t work well together. So yourFacesServletmapping should have only this:As a different alternative, replace the mapping on
*.jsfby*.xhtmland stick to using
*.xhtmlin all URLs/links throughout your website and remove the<security-constraint>on*.xhtml. With a mapping on*.xhtmlthe endusers will never see the raw source anyway. Every single XHTML file will be passed through theFacesServlet.Unrelated to the concrete problem, as per your comment on the other question you seem to have a meta refresh on the index page. This makes little sense. Just add
<welcome-file>home.xhtml</welcome-file>to the<welcome-file-list>. This works fine if you’ve mappedFacesServleton*.xhtml.