Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2 ManagedProperty injection of bean from dependency jar

I'm trying to get a ManagedProperty injection working, where the injected bean resides in a jar included in my web application.

Bean to be injected:

@ManagedBean(name="messages")  
@SessionScoped  
public class Messages implements Serializable
{

Receiving bean:

@ManagedProperty(value="#{messages}")
private Messages messages;

public void setMessages(Messages messages)
{
    this.messages = messages;
}

However, this doesn't work and I'm just getting the message "Unable to set property messages for managed bean". If I put the Messages class in the same package as the receiving bean instead of having it in it's own jar, it works just fine.

like image 213
Robert Avatar asked Mar 02 '11 13:03

Robert


1 Answers

The JAR must contain a JSF 2.0 compliant /META-INF/faces-config.xml file to trigger JSF 2.0 annotation scans in JAR files.

<?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>
like image 163
BalusC Avatar answered Oct 23 '22 09:10

BalusC