Primefaces components not showing at all [duplicate] - jsf

This question already has an answer here:
One or more resources has the target of 'head' but not 'head' component has been defined within the view
(1 answer)
Closed 7 years ago.
I recently started a new project and want to use primefaces components again. I used them for an other project before but now i dont know what I am missing.
My primefaces components are not rendering correctly.
I cant even get a simple Spinner to work.
I installed primefaces just like the last time adding the .jar to the namespace -> putting it in web-inf/lib
Here is what i tried so far:
Different Glassfish (4.0/3.1)
Different Primefaces Versions (4.0/3.5)
<?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"
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>SocialMapS</display-name>
<welcome-file-list>
<welcome-file>test.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app
web.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_1.xsd"
version="2.1">
</faces-config>
faces-config.xml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<head>
<title>SocialMap</title>
</head>
<h:body>
<p:spinner />
</h:body>
</html>
login.xhtml
Webpage I created to test if its working.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SocialMap</title>
</head><body><span id="j_idt4" class="ui-spinner ui-widget ui-corner-all"><input id="j_idt4_input" name="j_idt4_input" type="text" class="ui-spinner-input ui-inputfield ui-state-default ui-corner-all" autocomplete="off" /><a class="ui-spinner-button ui-spinner-up ui-corner-tr ui-button ui-widget ui-state-default ui-button-text-only"><span class="ui-button-text"><span class="ui-icon ui-icon-triangle-1-n"></span></span></a><a class="ui-spinner-button ui-spinner-down ui-corner-br ui-button ui-widget ui-state-default ui-button-text-only"><span class="ui-button-text"><span class="ui-icon ui-icon-triangle-1-s"></span></span></a></span><script id="j_idt4_s" type="text/javascript">PrimeFaces.cw('Spinner','widget_j_idt4',{id:'j_idt4'});</script></body>
</html>
Sourcecode in Firefox. Its just showing a textinput but not the spinner.
EDIT
WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=null[severity=(ERROR 2), summary=(One or more resources have the target of 'head', but no 'head' component has been defined within the view.), detail=(One or more resources have the target of 'head', but no 'head' component has been defined within the view.)]
The error I get
I even tried different webbrowser. No success.
I bet its a very simple mistake or I m missing something, but I didnt find it in the last 5 hours. ;-)
Pls help me.
EDIT
got the problem.... was as trivial as it can get.
Should have used
<h:head>
instead of
<head>
....
-_-

This is a bug for the version < 3.5. If you use the version 4.0.x it will run well.
If you are using eclipse, remind to do this steps to add the libraries in your WEB-INF/lib:
go to Project Properties / Project Facets / Java Server Faces
in type, select "User Library"
click in "Manage Library" icon,
than click in New,
put a name, click in OK
click in your recent created library
click in Add external JARs
select the javax.faces.jar and pramefaces-4.0jar in your User Library, "OK"
Click in "Apply" next in "OK"
in menu bar go to Project/Clean...
Now just run your server and have fun.

Simply replace <head> by <h:head> and </head> by </h:head>

Related

No warning or error on missing bean in tomcat

I have a very simple "dynamic web application" which results in a war-file. I (deliberately) used the name of a non-existing bean (for experimentation and learning purpose). When deployed to tomcat I can see the page in firefox, but I get no error or warning neither in catalina.out nor in catalina*.log.
What is wrong, where can I see such warnings?
I'm using java 8, tomcat 8, eclipse 4.5.1 (mars), jsf-api.2.2.8.jar and jsf-impl.2.2.8.jar.
I don't have any java code of my own (yet), especially no beans.
The index.xhtml that is used (and, aside of the missing bean value) displayed correctly is:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<ins>This is some other xhtml</ins>
<h:commandButton value="A#{missingBean.name}Z" action="#{missingBean.doAction}"></h:commandButton>
<h:messages></h:messages>
</body>
</html>
EDIT:
thanks to #Kukeltje I added
<context-param>
<param-name>javax.faces.DEVELOPMENT_STAGE
</param-name>
<param-value>Development</param-value>
</context-param>
to my web.xml file.
This results in an
HTTP Status 500 - javax.el.PropertyNotFoundException: /index.xhtml #13,81 action="#{missingBean.doAction}": Target Unreachable, identifier 'missingBean' resolved to null.
This solved the original problem that I didn't get errors nor even warnings on an obvious (and deliberate) coding error.
Background information: I try to learn jsf and did some experiments based on a tutorials-point tutorial. Having messed that up by trying far too many things in one go, I resolved to start a new eclipse project from scratch, going very tiny step by step, to see not only the result (as would be by blindly doing copy&paste), but also what errors I'll see if I neglect something on the way.

Getting NullPointerException and FacesContext not found error in f:view tag [duplicate]

I don't know how to continue, but I always get the "java.lang.RuntimeException: Cannot find FacesContext" for my new JSF 1.2 web application. I'm sure it's just some configuration I can't find.
The exception occurs with the first f: or h: tag. Already with the important <f:view> at the beginning.
My index.jsp
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<f:view>
<html>
<head>
<title>MyWebsite</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<div>MyContent</div>
</body>
</html>
</f:view>
My web.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jsp</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>720</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
And then I also have a faces-config.xml that should reference myBean I want to use afterward in the body of the page:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
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">
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
<managed-bean>
<managed-bean-name>myClassName</managed-bean-name>
<managed-bean-class>
com.company.className
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
What am I missing here?
java.lang.RuntimeException: Cannot find FacesContext
Thus, the JSF <f:xxx> and <h:xxx> tags are complaining that FacesContext cannot be found. The FacesServlet is the one responsible for creating the faces context. The faces servlet is invoked when the request URL matches its URL pattern, which is in your particular case *.jsf. So, when you open the index.jsp as http://localhost:8080/context/index.jsp, or are relying on the <welcome-file> setting, then you are not invoking the faces servlet and you would indeed get this exception.
You need to open the index.jsp as http://localhost:8080/context/index.jsf, or to set the welcome file entry to index.jsf in order to properly invoke the faces servlet, so that it can create the faces context which is required by the JSF components declared in the JSP page.
Note however that only fixing the welcome file isn't sufficient in this JSF 1.x + Tomcat environment. You also need to supply a physically existing, but completely empty index.jsf file next to the index.jsp file in the webcontent in order to fool Tomcat that index.jsf really exists as welcome file. It would otherwise show a 404 error because it checks the physical presence of the welcome file beforehand.
See also:
javax.faces.FacesException: java.lang.RuntimeException: Cannot find FacesContext
Unrelated to the concrete problem, I'm wondering why you're using JSP if you've apparently installed Facelets 1.x and registered its view handler. Facelets is far superior to JSP.

I cant use JSF 2.1.3 <f:event> capability

Building a WEB application using JSF 2,Spring 2.5,Maven 3,RichFaces,facelets
Ive been searching for answers and to no avail ended up with nothing,
Ive been looking into my libraries version too,i think Im missing something.
i just want to try out this new <f:event> tag for JSF 2
here are my specs
tomcat 7.0.27
jstl-api-1.2.jar
jstl-impl-1.2.jar
jsf-api-2.1.3.jar
jsf-impl-2.1.3.jar
jsf-facelets-1.1.10.jar
richfaces-api-3.3.3.jar
richfaces-impl-3.3.3.jar
richfaces-ui-3.3.3.jar
xhtml file
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.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">
faces-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">
here is block of my stack trace:
com.sun.facelets.tag.TagException: /twofalogin.xhtml #18,71 <f:event> Tag Library supports namespace: http://java.sun.com/jsf/core, but no tag was defined for name: event
FYI:
Ive tried using the exact same libs as a simpe JSF 2 project on eclipse without maven
and using JSP instead of xhtml, i could find the <f:event> on eclipse auto complete.
I havent tried running it on my tomcat though.
Thanks

Strange behaviour while running JSF "Hello World"

When running my JSF "Hello World" in server I get a File download message box which says "do you want to save this file, or find a program online to open it" which has three options find, save and cancel. When I click on 'find' following message is shown
"Windows has the following information about this MIME type. This page will help you find software needed to open your file.
MIME Type: application/xhtml xml
Description: UnKnown
Windows does not recognize this MIME type."
my xhtml is
<?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 lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Insert title here</title>
</h:head>
<h:body>
<f:view>
<h:outputText value="Hello World"></h:outputText>
</f:view>
</h:body>
</html>
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"
id="WebApp_ID" version="3.0">
<display-name>hospital</display-name>
<welcome-file-list>
<welcome-file>login.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>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
If I run that particular xhtml file then its shown in IE. But any update to xhtml file will will be shown after refreshing the IE.
I am using Eclipse-helios IDE, Glassfish webserver. Thanks in advance
MSIE does indeed not support the content type of application/xhtml+xml. The page should be served with a content type of text/html (you can verify that with HTTP/web developer tools). But that should already be done by default JSF/Facelets configuration. You don't seem to have overridden the content type anywhere in the given code. One of the ways is defining it using the contentType attribute of the <f:view> tag. Another way is calling HttpServletResponse#setContentType() in some web filter. Or, completely different, perhaps it's been done afterwards by the webserver itself or by some proxy in the line.

JSF tags not being rendered as HTML [duplicate]

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.

Resources