如何将注释与faces-config.xml混合 [英] How to mix annotations with faces-config.xml

查看:129
本文介绍了如何将注释与faces-config.xml混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JBoss 6.0.0.Final,Richfaces 3.3.3.Final,MyFaces 2.0.6,Facelets 1.1.15.B1(RF 3的限制).

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).

我在一个旧项目中,该项目包含数百个在faces-config.xml中定义的bean.我想将这些定义保留在faces-config.xml中,但对新bean使用注释.但是,当我尝试这样做时,我还没有成功.注释定义的Bean,即

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.

@ManagedBean
@ViewScoped
public class Foobar implements Serializable {
    // ...
}

无法从我的JSF页面访问该bean.我相信我已经通过使用正确的标头在我的faces-config.xml中指定了2.0版本.

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

faces-config.xml中我还需要做其他事情以允许使用批注吗?

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

推荐答案

在以下情况下,带注释的bean将失败:

Annotated beans will fail in the following cases:

  1. /WEB-INF/faces-config.xml未声明符合JSF 2.0.

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

@ManagedBeanjavax.annotation软件包,而不是javax.faces.bean.

Bean类未编译/内置到WAR的/WEB-INF/classes中.

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

Bean被打包在缺少/META-INF/faces-config.xml的JAR文件中.

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

EL中使用了错误的托管Bean名称,它应该是Java类规范中具有第一个字符小写的Bean类名称.因此,在您的特定示例中,#{fooBar}应该有效,但#{FooBar}无效.

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.

Webapp实际上是使用JSF 1.x库(您可以在服务器启动日志中阅读JSF版本)的.

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

这篇关于如何将注释与faces-config.xml混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆