OmniFaces complains about missing CDI and empty beans.xml - jsf

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?

Related

How to set elementFormDefault when publising a javax.jws.WebService in JBoss EAP 7

I've just switched my webapp from Weblogic 10.3.6 to JBoss EAP 7.3 and it tourns out that when asking for wsdl once the app is deployed the wsdl is generated with elementFormDefault="unqualified" :
xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://business.fornitori.infogroup.it/"
elementFormDefault="unqualified"
targetNamespace="http://business.fornitori.infogroup.it/"
version="1.0">
where the same WS deployed on WebLogic doesn't appear.
This cause the error at runtime :
SEVERE [com.sun.xml.messaging.saaj.soap.impl] (default task-7) SAAJ0131: HeaderElements must be namespace qualified
does any one runned into this error and knows how to solve it ?
I've tryied switching from Jaxws-rt 2.1.7 to Jaxws-rt 2.2.8 but didn't sole the problem

JSF faces flow throws the error "Flow already exists"

My environment:
JSF 2.3, Mojarra 2.3.9.payara-p2
PrimeFaces 7.0
Payara 5.192
OmniFaces 3.3
Project Java EE 8 Maven
NetBeans 11.1
I have created a Faces flow:
folder "flotTransfer" containing only 2 files (for the moment) flotTransfert-flow.xml and flotTransfert.xhtml.
I can't deploy the application. I receive this message:
"
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: java.lang.IllegalStateException: Flow with id "flotTransfert" and definingDocumentId "" already exists.|#]
".
I don't understand why I get this error (why "already exists"?). No other application deployed on the server.
The content of flotTransfert-flow.xml:
<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">
<flow-definition id="flotTransfert">
<flow-return id="sortieFlot">
<from-outcome>/listeComptes</from-outcome>
</flow-return>
</flow-definition>
</faces-config>
If I rename this file, no more error and the application is deployed on the server but, obviously, the faces flow does not work.
If I keep the file but remove all the content of the file (I comment out all the lines), I get the same error.
I have almost the same faces flow (just more pages in the folder) in another application but with Java EE 7 and Payara 5.184 and without OmniFaces and the flow works.
Sorry, I made a mistake: I added the file flotTransfert-flow.xml with a wizard of my IDE and I didn't notice that this wizard added a <context-param> in the file web.xml, referencing the definition file of the flow. If I remove this <context-param>, all is working.
The lines I removed from web.xml:
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/flotTransfert/flotTransfert-flow.xml</param-value>
</context-param>

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

Upgrading my weld-servlet dependency from 1.1 to 2.2.9 .. common error shows up

I'm getting started with some CDI stuff (coming from a Spring background.) I'm following some war examples online and they typically use an older dependency of weld-servlet such as 1.1.10.Final.
When I use this dependency my sample app works just fine [Tomcat 7]. However, when I try to upgrade to 2.2.9.Final, I end up getting startup error:
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UserTransaction with qualifiers #Default
This happens only when I upgrade.
Currently in this simple webapp I have a single beans.xml file located under WEB-INF (although I also tried adding an extra one under META-INF as well.)
Any ideas what I might be be doing wrong.
It just seems so odd that it works fine under 1.1 but not 2.2 ?
My beans.xml I've tried defining two ways (not sure which one is better.. I've seen both)
<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="annotated"
>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_1.xsd">
</beans>

Is it possible to deploy JSF-Web-Apps in WSO2 AS 5.2?

I tried the following steps:
At first I installed the feature "WSO2 Carbon - J2EE Runtime Environment" in the AS. Then I created a new dynamic web project in Eclipse with Servlet Module 2.5 and a configuration for JSF 1.2 using Myfaces 1.2.9 and a JSF-HTML-Template. After I had written "hello" in the view, I tested it with "run on server" in Eclipse and it runs. Then I created a WAR-File and deployed it in the AS with pasting the file in "asroot/repository/deployment/server/webapps".
Then I tried the page and it throws this error:
"/NewFile.jsp(2,57) PWC6188: The absolute uri: http://java.sun.com/jsf/core cannot be resolved in either web.xml or the jar files deployed with this application
Caused by:
org.apache.jasper.JasperException - /NewFile.jsp(2,57) PWC6188: The absolute uri: http://java.sun.com/jsf/core cannot be resolved in either web.xml or the jar files deployed with this application"
I tried it also on a local Tomcat-Server with the same result like in Eclipse.
The libs in the WAR are:
javax.servlet.jsp.jstl-1.2.1.jar
javax.servlet.jsp.jstl-api-1.2.1.jar
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-discovery-0.4.jar
commons-logging-1.1.1.jar
myfaces-api-1.2.9.jar
myfaces-impl-1.2.9.jar
This could be a classloading issue. Please put webapp-classloading.xml file in META-INF directory of your web application with following configurations
<?xml version="1.0" encoding="ISO-8859-1"?>
<Classloading xmlns="http://wso2.org/projects/as/classloading">
<Environments>Tomcat</Environments>
</Classloading>
Refer http://docs.wso2.org/display/AS520/Webapp+ClassLoading

Resources