I cant use JSF 2.1.3 <f:event> capability - jsf

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

Related

JSF custom taglib <ui:insert/> takes no default value

I am trying to create a JSF custom tag in which it is possible (optionally) to nest some other data. I am working with <ui:insert/> which I know from templating (which is explained e. g. here JSF - template tags).
As far as I understand, you can declare a default content within <ui:insert/> which is going to be rendered if no content is defined. Furthermore I found an example for this usage in the OptimusFaces Library.
With that in mind I created a custom tag.
Tag: helloWorld.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<p>
Hello World:
<ui:insert>
default value
</ui:insert>
</p>
</ui:composition>
Taglib definition: myapp.taglib.xml
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
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-facelettaglibrary_2_2.xsd"
version="2.2">
<namespace>http://myapp.mycompany.com/ui</namespace>
<short-name>my</short-name>
<composite-library-name>composites</composite-library-name>
<tag>
<description>Test</description>
<tag-name>helloWorld</tag-name>
<source>resources/tags/helloWorld.xhtml</source>
</tag>
</facelet-taglib>
Usage: index.xhtml
<html ...
xmlns:my="http://myapp.mycompany.com/ui">
<my:helloWorld/>
<my:helloWorld>text</my:helloWorld>
...
</html>
Now I would expect the output of the first usage of the tag would be
Hello World: default value
And the output of the second usage would be
Hello World: text
But it is not. With the second tag everything is fine but the first tag seems to ignore the default value. The output is only Hello World: .
Question
Am I making a mistake or is it not possible to use the inserts as I want it to?

Primefaces components not showing at all [duplicate]

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>

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 define custom namespace for component declaration

when you use a component from extarnal libraries (or custom component) in JSF page you add the xmlns declaration, for example:
xmlns:util="http://java.sun.com/jsf/composite/component/util
I would like to know what I have to do to use a private address in the Namaspace like this below:
xmlns:p="http://primefaces.prime.com.tr/ui"
It is something related to packages? Or it depends from the name of the .JAR that contains the components?
Thank you!
For Facelets this is definied in .taglib.xml file. In case of PrimeFaces it's /META-INF/primefaces-p.taglib.xml:
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib 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-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://primefaces.prime.com.tr/ui</namespace>
...
Note the <namespace>. For JSP this is definied in the .tld file, for PrimeFaces it's the /META-INF/primefaces-p.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">
<tlib-version>1.2</tlib-version>
<short-name>p</short-name>
<uri>http://primefaces.prime.com.tr/ui</uri>
...
Note the <uri>.

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