开发者

How to mix annotations with faces-config.xml

Using JBoss 6.0.0.Final, Richfaces 3.3.3.Final, MyFaces 2.0.6, facelets 1.1.15.B1 (a limitation of RF 3).

I'm on a legacy project which contains hundreds of beans defined in faces-config.xml. I'd like to keep those defined in faces-config.xml but use annotations for new beans. However, when I've tried this I've not had success. The beans defined by annotation i.e.

@M开发者_StackOverflow中文版anagedBean
@ViewScoped
public class Foobar implements Serializable {
    // ...
}

The bean is not accessible from my JSF page. I believe I've specified the 2.0 version in my faces-config.xml by using the proper header.

<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">

Is there anything else I need to do in the faces-config.xml to allow annotations to also be used?


Annotated beans will fail in the following cases:

  1. /WEB-INF/faces-config.xml is not declared to conform to JSF 2.0.

  2. @ManagedBean is of javax.annotation package instead of javax.faces.bean.

  3. Bean class is not been compiled/built into WAR's /WEB-INF/classes.

  4. Bean is packaged in a JAR file which is missing /META-INF/faces-config.xml.

  5. A wrong managed bean name is being used in EL, it should be the bean class name with 1st character lower cased according Javabeans spec. So in your particular example, #{fooBar} should work, but #{FooBar} won't.

  6. Webapp is actually using JSF 1.x libs (you can read JSF version in server startup log).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜