I've written an application using Glassfish 3.1.2.2 and Primefaces 4.0. This is really at the start, so there's not much going on. I have added Form-based security. When I first did this, I had all of the xhtml pages in the same folder in my WAR file. I was able to logout by having the following methd in my UserBean
public String logout() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
session.invalidate();
return "welcomeRedir";
}
Where my faces-config.xml had the following navigation rule
<navigation-rule>
<navigation-case>
<from-outcome>welcomeRedir</from-outcome>
<to-view-id>/welcome.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
Where welcome.xhtml is the original Login page. And, when I had it defined this way, it worked. I could login using a JDBC realm and when I clicked the logout button, the page navigated back to the welcome page.
Next, I wanted to add security constraints. So, I moved the relevant pages (but not the welcome page) to subsdirectories, and added the appropriate security-constraint elements to the web.xml. And I can still log into those pages.
But, when I click the logout button, nothing happens. If I look at the network traffic being sent from the browser, it's getting a 403 error as a response.
I've looked and looked, but I can't find anything relevant. Has anyone gotten this to work when security-constraints are defined?
web.xml
<?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">
<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>*.xhtml</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- More efficient, in an AJAX environment, to have server side state saving -->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<!-- HTML comments become components unless they're stripped -->
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- PrimeFaces Theme -->
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>cupertino</param-value>
</context-param>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>welcome.xhtml</welcome-file>
</welcome-file-list>
<resource-ref>
<res-ref-name>jdbc/resmandb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<security-constraint>
<display-name>Protected Pages</display-name>
<web-resource-collection>
<web-resource-name>ApplicationPages</web-resource-name>
<url-pattern>/protected/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
<role-name>registeredUser</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<display-name>System Admin Pages</display-name>
<web-resource-collection>
<web-resource-name>SysAdminPages</web-resource-name>
<description/>
<url-pattern>/sysadmin/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>authentication-realm</realm-name>
<form-login-config>
<form-login-page>/welcome.xhtml</form-login-page>
<form-error-page>/welcome.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>A System Admin of ResMan</description>
<role-name>admin</role-name>
</security-role>
<security-role>
<description>A Registered User of ResMan</description>
<role-name>registeredUser</role-name>
</security-role>
</web-app>
faces-config.xml
<faces-config version="2.1"
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-facesconfig_2_1.xsd">
<application>
<resource-bundle>
<base-name>messages</base-name>
<var>msg</var>
</resource-bundle>
</application>
<navigation-rule>
<navigation-case>
<from-outcome>welcome</from-outcome>
<to-view-id>/welcome.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<navigation-case>
<from-outcome>welcomeRedir</from-outcome>
<to-view-id>/welcome.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<navigation-rule>
<navigation-case>
<from-outcome>reservations</from-outcome>
<to-view-id>/protected/reservations.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
As it turns out, it's nothing to do with the faces configuration and more about how my glassfish-web.xml defined its security-role-mapping elements. The values in the elements didn't match the groups contained within my JDBC Realm (ie, the names of the groups in my database tables). Once I defined these correctly, the logout works.
In truth, until I did this, none of the AJAX requests from Primefaces were being accepted. It wasn't a logout issue, it was a general interaction issue.
Related
I'm using JSF to make a website for a project, and I use subdirectories to manage what users are able to access which pages.
My WAR project is organized as follows:
+Web Pages
+User
movies.xhtml
+WEB-INF
//beans, faces-config, glassfish-web, and web.xml here
+images
+resources
+css
header.css
+templates
header.xhtml
index.xhtml
//other views
My navigation rules are as follows
<navigation-rule>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>movies</from-outcome>
<to-view-id>/User/movies.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-view-id>*</from-view-id>
<from-outcome>index</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
<from-outcome>create</from-outcome>
<to-view-id>/create.xhtml</to-view-id>
<from-outcome>help</from-outcome>
<to-view-id>/help.xhtml</to-view-id>
<from-outcome>login</from-outcome>
<to-view-id>/login.xhtml</to-view-id>
<from-outcome>search</from-outcome>
<to-view-id>/search.xhtml</to-view-id>
</navigation-case>
My web.xml servlet-mapping is as follows:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/vd/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>vd/index.xhtml</welcome-file>
</welcome-file-list>
Now, I have no problem with the navigation rule that brings me to /User/movies.xhtml. However, once I am in /User/movies.xhtml, JSF cannot find any of my pages (IE. index.xhtml). However, it can still find the template that movies.xhtml uses.
Why can't JSF find where other views are? How should I change my navigation rules so that it can find them?
I'm running on Glassfish v3.1.2.
I figured out what the problem is. I stopped using navigation cases and uses JSF 2's implicit navigation and everything worked as it should.
I am currently learning jsf. I have written A simple jsf application where my target is to navigate from one page to another page. However, I am unable to navigate at all.
In my code there are two jsp files; one is createcustomer.jsp and the other is viewCustomerDetails. After the user enters data in createcustomer.jsp and clicks on the button it should move to next page (where it will display entered data in previous page in this page).
Below is my code. Can anyone find where I'm going wrong?<
createCustomer.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td>
<h1 style="background-color:blue;color:white;">Create a new Customer</h1>
</td>
</tr>
</table>
<f:view>
<table>
<tr><td>Name:</td><td><h:inputText value="#{customer.name}"></h:inputText></td></tr>
<tr><td>Address:</td><td><h:inputText value="#{customer.address}"></h:inputText></td></tr>
<tr><td>Phone Number:</td><td><h:inputText value="#{customer.phNumber}"></h:inputText></td></tr>
<tr><td>Email Address:</td><td><h:inputText value="#{customer.email_id}"></h:inputText></td></tr>
</table>
<table>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><h:commandButton value="Create Customer" action="viewCustomerDetails" /></td></tr>
</table>
</f:view>
</body>
</html>
face-config.xml
<faces-config
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-facesconfig_2_0.xsd"
version="2.0">
<managed-bean>
<managed-bean-name>customer</managed-bean-name>
<managed-bean-class>com.app.view.Customer</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/createcustomer.jsp</from-view-id>
<navigation-case>
<!-- <from-action>#{customer.validate}</from-action> -->
<from-outcome>viewCustomerDetails</from-outcome>
<to-view-id>/viewCustomerDetails.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
web.xml
<?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" version="3.0">
<display-name>Customer</display-name>
<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>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<description>
This parameter tells MyFaces if javascript code should be allowed in
the rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default is 'true'</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
If true, rendered HTML code will be formatted, so that it is 'human-readable'
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default is 'true'</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>
If true, a javascript function will be rendered that is able to restore the
former vertical scroll on every request. Convenient feature if you have pages
with long lists and you do not want the browser page to always jump to the top
if you trigger a link or button action that stays on the same page.
Default is 'false'
</description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
</web-app>
Apparently, based on your code snipplet you have no <h:form> tag defined. Components such as <h:commandButton> need to be defined inside of one to function properly. Encase the content of your <f:view> inside an <h:form> and try again.
I have a JSF webapp which is exhibiting the following behaviour:
http://localhost/myapp/ returns the raw contents of index.xhtml
http://localhost/myapp/web/ returns a blank page
http://localhost/myapp/web/index.xhtml returns the error /index.xhtml Not Found in ExternalContext as a Resource
The directory structure of the webapp is shown below:
The web.xml file looks as follows:
<?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" version="3.0">
<display-name>myapp</display-name>
<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>/web/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!-- <welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
-->
</web-app>
I have a breakpoint in the first line of the method javax.faces.webapp.FacesServlet.service
public void service(ServletRequest req,
ServletResponse resp)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
requestStart(request.getRequestURI()); // V3 Probe hook
This breakpoint is never hit. Is anyone able to shed some light on what may be wrong here or some pointers on where I can start my investigations.
JSF will trim off own URL pattern from the request URL before finding the resource. You need to put /index.xhtml file exactly there where JSF expects it as per the error message: in /index.xhtml. So, outside the /web folder. Note that you can just keep using /web in request URL.
An alternative is to just map the FacesServlet on *.xhtml. This way you don't need to worry about virtual URLs.
See also:
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
I am trying to set up environment for Java/JSF app in my windows 7 machine. I am using eclipse juno with Jboss AS 7 downloaded from the eclipse market. Also I am using JDK 1.7.
I created a very simple app containing just a h:outputLabel tag. Everything looks fine until deployed and run, but the tag doesn't render. What I mean to say is that I am getting a blank page.
The jars I included for JSF are : jsf-api-2.1, jsf-impl-2.1.0-b03.jar,jsf-facelets-1.1.14.jar.
And the usual commons and jstl jars.
There are no errors or any exceptions. Am I missing anything here? Please pardon me if its too simple but this is just taking too much time.
EDIT:
My auto-created faces-config xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
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-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
My web xml:
<?xml version="1.0"?>
<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">
<display-name>test</display-name>
<welcome-file-list>
<welcome-file>NewFile.xhtml</welcome-file>
</welcome-file-list>
<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>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Thanks in advance.
The jars I included for JSF are : jsf-api-2.1, jsf-impl-2.1.0-b03.jar,jsf-facelets-1.1.14.jar. And the usual commons and jstl jars.
There are quite a lot of mistakes right here. First of all, you don't need and even should not include the JSF jars. Those are already part of Java EE, which is implemented by JBoss AS 7.
Secondly, you definitely don't need and absolutely should not use the separate Facelets jar in combination with JSF 2.x. Facelets is already part of JSF 2.x.
You also should not include the JSTL jar. That one too is provided by Java EE/Jboss AS. If with commons jars you mean Apache commons, then those are fine but they are NOT needed for JSF. Include them only if you want to use them directly in your application code.
If you would need any of those jars (you don't, but suppose), it's also best practice to take the latest ones if you're just starting. From the version numbers it kinda looks like you just took a random old version. But again, you don't need any of those jars. They are provided by Java EE/JBoss AS 7.
My auto-created faces-config xml:
You don't need an empty faces-config.xml. If you're just starting, it might be better to remove everything you don't need. If there's later something you need to configure, you can always add it.
My web xml:
For JSF you don't really need to map the FacesServlet to the extensions you used. Those are already the default. If you leave out the entire web.xml, your Facelets (.xhtml) page can be requested by changing the .xhtml extension to .jsf or .faces. E.g. if your page is 'NewFile.xhtml' you can request it using localhost:8080/NewFile.jsf or 'localhost:8080/NewFile.faces` or 'localhost:8080/faces/NewFile.xhtml'.
Unfortunately, the only (IMHO) useful mapping is NOT provided as a default by JSF 2.1 and for that one you do need to add a mapping entry in web.xml:
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Because your welcome page is NewFile.xhtml, you need either this *.xhtml mapping, OR you can remove the mapping entirely and change the welcome-file content to e.g. NewFile.jsf.
Update:
If the welcome page still doesn't show, there must be something else in your project that you either don't know about yourself or aren't showing us.
Try to start over with a very simple project and see if it works there:
In Eclipse, create a new Dynamic Web Project
Use project name: welcome and Target runtime: JBoss 7.1 Runtime
Delete WebContent/META-INF and WebContent/WEB-INF/lib
Copy the 3 files from http://arjan-tijms.omnifaces.org/2011/08/minimal-3-tier-java-ee-app-without-any.html to your project. Afterwards your workspace should look exactly like the one in the picture.
Add a WebContent/WEB-INF/web.xml with the following content:
<?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">
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>page.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Double check you have exactly 4 files in your entire 'welcome' project, not more and not less.
Deploy your project to JBoss AS 7.1. To be sure, right click on the runtime server in the Servers view and click on "Clean..." Start your server and request localhost:8080/welcome or localhost:8080/welcome/.
I just tested this locally using the exact same steps I outlined, and it worked.
This question already has an answer here:
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
(1 answer)
Closed 6 years ago.
I'm following the Java EE firstcup tutorial using Netbeans and Glassfish.
When I execute the JSF web tier I've been instructed to code, the browser gets the same JSF markup coded in the .xhtml file, and the tags are not rendered as HTML tags. I know this by using the view source code in my browser.
For example, for this code:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Page title here</title>
</h:head>
<h:body>
<h2>
<h:outputText value="#{bundle.WelcomeMessage}" />
</h2>
</h:body>
</html>
The browser should get something like:
<html ...>
<head>
<title>Page title here</title>
</head>
<body>
<h2>
the welcome message goes here
</h2>
</body>
</html>
Right?
Well, my browser is getting jsf code (the first piece of code above) and not the html code (the second piece of code above).
It seems to be a configuration problem in netbeans or glassfish but don't know what. Any ideas?
This is my web.xml file:
<?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>
<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>/firstcup/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>greetings.xhtml</welcome-file>
</welcome-file-list>
</web-app>
This is my faces-config.xml file:
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="2.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-facesconfig_2_0.xsd">
<application>
<resource-bundle>
<base-name>firstcup.web.WebMessages</base-name>
<var>bundle</var>
</resource-bundle>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>es</supported-locale>
</locale-config>
</application>
<navigation-rule>
<from-view-id>/greetings.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/response.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
Moreover:
The url I'm entering in the browser is http://localhost:8081/firstcup/ but I've also tried: http://localhost:8081/firstcup/greetings.xhtml
I've checked Glassfish logs and there's no information about not being able to load FacesServlet
If JSF tags are not been parsed, then it simply means that the request has not been passed through the FacesServlet. That servlet is the one responsible for all that JSF stuff. You need to verify if the request URL used matches the url-pattern of the FacesServlet. Note that it is case sensitive.
This may however also happen if you opened the file directly in the builtin browser of the IDE. You shouldn't do that. You need to specify the right URL yourself in the address bar of either the builtin browser or an external browser (e.g. MSIE/Firefox).
Update: one more thing, did you declare the JSF HTML taglib in <html xmlns> attribtue? You omitted that in your code snippet.
It should look like
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
The following code in web.xml
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
instead of faces/* has solved my problem of non-rendered jsf tags.
Note: *.html causes stackoverflow
Check either your web.xml or your faces-config.xml. Something's obviously missing.
edit :
i don't know jsf 2, but in my jsf 1 faces-config.xml i have this :
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
Maybe you should take a look a this. (could be a hint, sorry i cannot help any further)
edit 2 : this is not the answer, sorry
SOLVED: Changing the welcome-file in web.xml to the following solved the problem:
<welcome-file-list>
<welcome-file>firstcup/greetings.xhtml</welcome-file>
</welcome-file-list>
This may not be relevant to you, but after hours of searching for the solution for a similar problem, my culprit turns out to be this file in WEB-INF/faces-config.xml :
<?xml version="1.0"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
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-facesconfig_1_2.xsd"/>
For some strange reason JBoss Tools 3.3.0.M2 put that file in my JSF 2.0 project and BOOM! Nothing works. The file looks very innocent yet (probably due to version="1.2") it made me quite frustrated.
I've searched logs (nothing!), WEB-INF/lib, classpaths, even removing dependencies and it turned out to be a single faces-config.xml :-P
Hopefully this helps someone...
I have also suffered from problem of jsf tags, not rendered at all. I used welcome file in web.xml as login/entry.xhtml.
When I changed that file to faces/login/entry.xhtml, it is working well.
It must be due to facesServelet is not intercepting the page.
It leads to rendering of only plain html and jsf tags are simply ignored.
Thanks #hendy-irawan
I solved my issue by changed my faces-config header
From
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
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-facesconfig_1_2.xsd"
version="1.2">
</faces-config>
To
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
I had the same problem. I deleted some richfaces jars from the WEB-INF/lib and JSF is working now.