JSF 2.2 namespace not found - jsf

i want to use the f:viewAction of JSF 2.2, but it is not working.
my faces-config:
<faces-config version="2.2"
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">
xhtml-definition:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:metadata>
<f:viewAction action="#{bean.welcomeUser()}" onPostback="false" />
</f:metadata>
...
</html>
the problem is that it underlines the f, h and the ui-namespace (with a warning: NLS missing message: CANNOT_FIND_FACELET_TAGLIB in:
org.eclipse.jst.jsf.core.validation.internal.facelet.messages)
what can I do to make it work again? ( i have included myfaces-impl-2.2.0 and the myfaces-api-2.2.0)
EDIT:
When i include jsf impl 2.2 and api 2.2 to my project, the warning disappears, but then the compiling gets big problems (factory not found etc)

Your described behaviour still persists in MyFaces 2.2.8, the problem with f:viewAction is well known. It should be fixed in Eclipse 3.7.2 (Mars.2) and MyFaces 2.2.9.
You have no Eclipse autocompletion for the tag, but you can actually use it as expected.
Reference:
https://issues.apache.org/jira/browse/MYFACES-4011
https://bugs.eclipse.org/bugs/show_bug.cgi?id=473856

Related

Changing faces-config.xml from 2.2 to 2.3 causes javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bean' resolved to null

Have the following code snippets:
Bean:
import javax.faces.view.ViewScoped;
import javax.inject.Named;
#Named(value = "directoryBean")
#ViewScoped
public class DirectoryBean implements Serializable {
private static final long serialVersionUID = 1L;
....
}
faces-config.xml
<?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_3.xsd"
version="2.3">
....
</faces-config>
group.xhtml
<ui:composition ...>
<f:metadata>
<f:viewParam name="id" value="#{directoryBean.id}" />
</f:metadata>
</ui:composition>
In result getting the exception:
javax.el.PropertyNotFoundException: /group.xhtml #6,64 value="#{directoryBean.id}": Target Unreachable, identifier 'directoryBean' resolved to null
Got it after changing faces-config.xml from ver 2.2 to ver 2.3 syntax.
Meaning, with faces-config.xml with the following content everything works fine:
<faces-config version="2.2" 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">
....
</faces-config>
JSF 2.3.2 deployed on the Payara 4.1.2.172 (Full) server, and also added to pom.xml with "provided" scope.
....
<dependencies>
...
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
...
</dependencies>
....
I have checked all solutions that I was able to find during several hours, including different version of beans.xml:
initially beans.xml was not present in the project - issue
persist;
added empty beans.xml - issue persist;
added beans.xml with two different options of bean-discovery-mode - "all"
and "annotated" - issue persist;
Content of \WEB-INF\beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
Tested on local instances of Payara 4.1.2.172, GlassFish 5 (java ver 1.8.0_144), and remote instance of Payara 4.1.2.172 (java ver 1.8.0_131).
Thanks!
Note: Example projects like this one https://github.com/AnghelLeonard/JSF-2.3/tree/master/JSF23InjectInConverterValidator give the same error.
===
Update as of 2022-03-31:
Got another error related to this issue on Payara 5.2022.1:
org.glassfish.deployment.common.DeploymentException: CDI deployment failure:WELD-001408: Unsatisfied dependencies for type UIViewRoot with qualifiers #Default
So seems even on the latest version of Payara JSF 2.3 is not enabled by default, as was mentioned in one of the comments below.
Adding it here for better searching visibility. :)
I would like to post a complete solution, what should be done in order to make JSF 2.3 libs work in JSF v2.3 mode. Code samples below are based on GlassFish 5.0 server environment.
1) Upgrade JSF libs to the version 2.3.3 at least (it fixes some bugs related to jsf 2.3 mode activation)
2) The beans.xml should look like:
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_2_0.xsd"
bean-discovery-mode="all" version="2.0">
</beans>
3) faces-config.xml should look like:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.3"
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_3.xsd">
....
</faces-config>
4) And the key-player in all this setup - is specially formed Java class that actually activates JSF 2.3 mode, in my case it has name Jsf23Activator and absolutely empty content:
package ua.local.beans;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.annotation.FacesConfig;
#ApplicationScoped
#FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class Jsf23Activator {
}
The annotation #FacesConfig(version = FacesConfig.Version.JSF_2_3) is added once per project, no need to add it several times.
Basically the need to add this annotation was mentioned several times by others, but in my case it didn't work until I declared this class as CDI bean by adding annotation #ApplicationScoped. Only after I declared the class as CDI bean, cleared project / restarted server - the JSF 2.3 mode finally got activated and now I am able to inject JSF classes / utilize other JSF 2.3 features!
I had this problem because after the update of JSF i still had this jar in my classpath :
el-impl-2.1.2.jar
After deleting this one the problem went away.
in DirectoryBean add this line:
// Activates CDI build-in beans
#FacesConfig(
version = JSF_2_3
)
and in beans.xml change bean-discovery-mode to "all". faces-config.xml set version 2.3
Solution 2:
switch to Payara 5.183, it works out of the box. No need for solution 1: Jsf23Activator

xmllint fails to validate XHTML 1.0 Transitional file

Steps to reproduce on Debian Jessie GNU/Linux.
Check xmllint version:
$ xmllint --version
xmllint: using libxml version 20901
compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib Lzma
Make an XHTML 1.0 Transitional file by saving this as example.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>A title</title>
</head>
<body>
Some content
</body>
</html>
N.B. Pasting the contents of example.xhtml into the W3C Validator yields "This document was successfully checked as XHTML 1.0 Transitional!", so it should also validate when using xmllint.
xmllint online validation
This fails, despite the fact that the computer has internet access:
$ xmllint --noout --valid example.xhtml
example.xhtml:1: warning: failed to load external entity "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
^
example.xhtml:2: validity error : Validation failed: no DTD found !
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
^
xmllint offline validation
Install XHTML 1.0 DTDs and entity files:
$ wget -qO- https://www.w3.org/TR/xhtml1/xhtml1.tgz | tar xvz
xhtml1-20020801/
xhtml1-20020801/W3C-REC.css
xhtml1-20020801/xhtml.css
xhtml1-20020801/logo-REC.png
xhtml1-20020801/w3c_home.png
xhtml1-20020801/wcag1AAA.png
xhtml1-20020801/acks.html
xhtml1-20020801/Cover.html
xhtml1-20020801/definitions.html
xhtml1-20020801/diffs.html
xhtml1-20020801/dtds.html
xhtml1-20020801/guidelines.html
xhtml1-20020801/introduction.html
xhtml1-20020801/issues.html
xhtml1-20020801/normative.html
xhtml1-20020801/Overview.html
xhtml1-20020801/prohibitions.html
xhtml1-20020801/references.html
xhtml1-20020801/xhtml1-diff.html
xhtml1-20020801/DTD/
xhtml1-20020801/DTD/xhtml-lat1.ent
xhtml1-20020801/DTD/xhtml-special.ent
xhtml1-20020801/DTD/xhtml-symbol.ent
xhtml1-20020801/DTD/xhtml.soc
xhtml1-20020801/DTD/xhtml1-frameset.dtd
xhtml1-20020801/DTD/xhtml1-strict.dtd
xhtml1-20020801/DTD/xhtml1-transitional.dtd
xhtml1-20020801/DTD/xhtml1.dcl
xhtml1-20020801/xhtml1.ps
xhtml1-20020801/xhtml1.pdf
Still fails:
$ xmllint --noout --dtdvalid xhtml1-20020801/DTD/xhtml1-transitional.dtd example.xhtml
example.xhtml:1: warning: failed to load external entity "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
^
Likewise if using the --nonet option:
$ xmllint --noout --nonet --dtdvalid xhtml1-20020801/DTD/xhtml1-transitional.dtd example.xhtml
I/O error : Attempt to load network entity http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
example.xhtml:1: warning: failed to load external entity "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
^
Questions
I have two questions:
Why did none of these validation attempts succeed?
The second one seems to fail because despite using the --dtdvalid option, xmllint still tries to visit http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd because it is referenced in example.xhtml. Is there some way to tell xmllint to ignore that reference and to instead use a local DTD (e.g. the one already stored at xhtml1-20020801/DTD/xhtml1-transitional.dtd?
It seems the simplest workaround is:
$ sudo apt-get install w3c-dtd-xhtml
This installs the relevant DTDs locally. Thereafter, validation succeeds:
$ xmllint --noout --valid example.xhtml
$
However, although this allows me to validate the XHTML file, it does not really answer the questions. Therefore, I will not mark this question as "answered", in the hope that someone will provide an answer that does indeed answer them.

OmniFaces complains about missing CDI and empty beans.xml

I like to add omnifaces to my tomcat8 webapp but omnifaces seems to complain either about a missing CDI implementation or about not being able to parse beans.xml (some SAXParserException). Currently I have the following libraries under WEB-INF/lib:
BootsFaces-OSP-0.8.1-dist-default.jar
cdi-api-1.2.jar
javax.el-api-3.0.1-b04.jar
javax.inject-1.jar
javax.interceptor-api-1.2.jar
jsf-api-2.2.11.jar
jsf-impl-2.2.11.jar
jstl-1.2.jar
omnifaces-2.2.jar
primefaces-5.3.jar
weld-core-2.3.3.Final.jar
weld-servlet-2.3.3.Final.jar
weld-servlet-core-2.3.3.Final.jar
Currently I have two issues with this setup:
a real emtpy beans.xml leads to the "nope, please install CDI" error
the following "empty" beans.xml leads to a "cannot parse beans.xml" error
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_2.xsd"
bean-discovery-mode="annotated"></beans>
The documentation how to install CDI is from 2013 which is kind of outdated in my eyes.
What is wrong or missing in my setup and where to read on how to get omnifaces running in tomcat8?

Problens with #named on cdi [duplicate]

This question already has answers here:
How to install and use CDI on Tomcat?
(2 answers)
Closed 7 years ago.
good afternoon every body, I'm stucked on the following problem...
I have to use jsf and cdi on a project, I've seen that when i use cdi i should be usign the #named instead of #ManagedBean, but when i change it the message is no longer shown on the browser.
it is just a test for now, so it has no complex code and stuff.
here is my index:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 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">
<h:head>
<title>Hello JSF!</title>
</h:head>
<h:body>
<h:outputText value="#{teste.message}" />
</h:body>
</html>
here is my bean:
package jsfConnection;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
#Named("teste")
#RequestScoped
public class Teste {
public String getMessage() {
return "ola";
}
}
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"
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">
<description>Patrimônio web.xml</description>
<!-- Nome da sua aplicação -->
<display-name>Patrimônio</display-name>
<!-- Faces Servlet -->
<!-- Configuração do arquivo inicial quando a aplicação for inicializada -->
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
<!-- Configuração do Controlador Faces Servlet -->
<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>
when i use #ManagedBean it shows normally but when i switch to #Named it simply does not print anything...
This is a duplicate of "How to install and use CDI on Tomcat?". Please note that I attempted to make some detailed instructions on my Blog: "Enabling JSF 2.2 and CDI 1.2 on Tomcat 8". These instructions should work for Tomcat 7 too, although I did not test. I might also be good to note that you might be better off using a version of TomEE, which already comes packaged with an implementation of CDI and JSF.
See the Blog for more detailed information, but setting it all up on Tomcat requires 2 main steps:
Defining the right provided and runtime libraries as your maven dependencies
Configure and Bootstrap the CDI Implementation (Weld).
Setting up bootstrapping happens using the following 3 files:
WEB-INF/web.xml
WEB-INF/beans.xml
META-INF/context.xml - This META-INF directory can be found at the webapp root, or the same location where WEB-INF can be found.
Note also that as part of the web.xml file, you define how requests (URL's) are mapped to a physical location (path). The <servlet-mapping> for your Faces Servlet, which can be either as a path prefix, or as an extension: <url-pattern>/faces/*</url-pattern> vs <url-pattern>*.xhtml</url-pattern>.
Tomcat is not a Java EE server, so CDI doesn't work out of the box. To use CDI in it, you need to 1) include a CDI implementation and 2) configure it in web.xml.
See the documentation of your CDI implementation (Weld or OpenWebBeans) for details.

How to run a JSF 2.2 page in Java EE 7 environment without web.xml?

What is wrong with my very very simple web app: web app successfully deployed to app server but hello bean did not inject to index.xhtml page
(page shows just Hello from Facelets: #{hello.value})?
(this is first time when I am working with JSF, so maybe this question is very easy, and also I used good article http://arjan-tijms.omnifaces.org/2011/08/minimal-3-tier-java-ee-app-without-any.html )
I have the next structure of war archive:
mywebapp
|
- WEB_INF
|
- classes
|
- Hello.class
- index.html
Hello.java has:
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
#Named
#RequestScoped
public class Hello {
private String value;
public String getValue() {
return "Hello JSF";
}
public void setValue(String value) {
this.value = value;
}
}
and also my index.xhtml
<?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 xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>My Facelet Page Title</title>
</h:head>
<h:body>
Hello from Facelets: #{hello.value}
</h:body>
</html>
For building project I used pom.xml:
....
<packaging>war</packaging>
<name>Simple web app</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Taken from JavaServerFaces 2.0, The Complete Reference:
An entry in the Web application’s web.xml file enables the Faces Controller servlet
when a certain URL pattern is specified, such as /faces/. When running JSF 2.0 on
a Servlet 3.0 container, such as Sun’s Glassfish v3, the web.xml is optional. If no
web.xml is found, the Faces Controller servlet is automatically mapped to the most
popular URL patterns: /faces/, .jsf, and .faces.
So you should try with something like this:
localhost:8080/mywebapp/faces/index.xhtml.
According to the javadoc, FacesServlet will be automatically registered if any of the following conditions are true:
A faces-config.xml file is found in WEB-INF
A faces-config.xml file is found in the META-INF directory of a jar in the application's classpath.
A filename ending in .faces-config.xml is found in the META-INF directory of a jar in the application's classpath.
The javax.faces.CONFIG_FILES context param is declared in web.xml or web-fragment.xml.
The Set of classes passed to the onStartup() method of the ServletContainerInitializer implementation is not empty.
If you are using web.xml only for registering FacesServlet, then it would be optional if any of the above conditions are met.

Resources