CDI的表达语言不起作用

时间:2014-09-17 16:50:44

标签: glassfish websphere el cdi

我有一个包含战争的简单耳文。我只有一个Named-Bean和一个xhtml。 在玻璃鱼上一切正常。但是在websphere上它不起作用。 我的工作并不意味着所有EL-Tag都会被忽略。当我删除/ WEB-INF中的beans.xml时,我可以在glassfish中重现这个。我试图将beans.xml放在每个文件夹中。

我读了这篇文章(http://www.ibm.com/developerworks/websphere/techjournal/1301_stephen/1301_stephen.html):

  

beans.xml文件必须放在以下位置之一:       对于库JAR,EJB JAR,应用程序客户机JAR或RAR存档,它需要位于META-INF目录中。       WAR的WEB-INF / classes目录。       对于包含类的JVM类路径中的目录,如果beans.xml文件位于META-INF子目录中,则将扫描代码。

但没有任何作用。当我使用@ManagedBean和Faces Session Scope时,一切正常。 我不知道自己能做些什么。请帮忙。

这是我的示例代码和我的结构:

XHTML:

<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:p="http://primefaces.org/ui">
<h:head>

</h:head>

<h:body>
 <h:form id="tableform">
    <h:outputText value="TEST"/>
    <h:outputText value="#{personBean.helloWorld}"/>
    <p:commandButton value="#{personBean.helloWorld}"/>
</h:form>
</h:body>
</html>

豆:

@Named
@SessionScoped
public class PersonBean implements Serializable{

private String helloWorld;


@PostConstruct
public void init() {
    setHelloWorld("HELLO WORLD");
}


public String getHelloWorld() {
    return helloWorld;
}


public void setHelloWorld(String helloWorld) {
    this.helloWorld = helloWorld;
}
}

结构

耳 -Meta-INF --Application.xml -战争 --Web-INF --- beans.xml中

但我试图把它放在WEB-INF / classes,META-INF,META-INF中。什么都行不通。 :(

带有beans.xml的Glassfish结果:

enter image description here

没有beans.xml的Websphere / Glassfish上的结果:

enter image description here

我没有例外或错误或其他。

1 个答案:

答案 0 :(得分:1)

WebSphere 8.x捆绑了JSF实现(MyFaces),只有该默认实现与CDI一起使用。您需要在beans.xml文件夹中包含WEB-INF

但是根据您的网页片段,您使用的是自定义页面(PrimeFaces) 查看此页面了解更多详情:CDI integration with JavaServer Faces