Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 如何在EJB模块中调用支持bean_Jsf_Jakarta Ee_Glassfish_Ejb_Facelets - Fatal编程技术网

Jsf 如何在EJB模块中调用支持bean

Jsf 如何在EJB模块中调用支持bean,jsf,jakarta-ee,glassfish,ejb,facelets,Jsf,Jakarta Ee,Glassfish,Ejb,Facelets,当我运行应用程序时,计数器按预期递增,但是如何将bean从web模块移动到ejb模块 一般结构: NetBeansProjects/EntAppWeb/ ├── build.xml ├── EntAppWeb-ejb │   ├── build.xml │   ├── nbproject │   │   ├── ant-deploy.xml │   │   ├── build-impl.xml │   │   ├── genfiles.properties │   │   ├── private

当我运行应用程序时,计数器按预期递增,但是如何将bean从web模块移动到ejb模块

一般结构:

NetBeansProjects/EntAppWeb/
├── build.xml
├── EntAppWeb-ejb
│   ├── build.xml
│   ├── nbproject
│   │   ├── ant-deploy.xml
│   │   ├── build-impl.xml
│   │   ├── genfiles.properties
│   │   ├── private
│   │   │   ├── private.properties
│   │   │   └── private.xml
│   │   ├── project.properties
│   │   └── project.xml
│   └── src
│       ├── conf
│       │   └── MANIFEST.MF
│       └── java
├── EntAppWeb-war
│   ├── build.xml
│   ├── nbproject
│   │   ├── ant-deploy.xml
│   │   ├── build-impl.xml
│   │   ├── genfiles.properties
│   │   ├── private
│   │   │   ├── private.properties
│   │   │   └── private.xml
│   │   ├── project.properties
│   │   └── project.xml
│   ├── src
│   │   ├── conf
│   │   │   └── MANIFEST.MF
│   │   └── java
│   │       └── dur
│   │           ├── database
│   │           │   ├── Clients.java
│   │           │   ├── ClientsQueryBean.java
│   │           │   └── QueryBeanWithEntityManager.java
│   │           └── facelets
│   │               ├── DirectoryBean.java
│   │               ├── Hello.java
│   │               └── MyQueueBean.java
│   └── web
│       ├── eagle.xhtml
│       ├── falcon.xhtml
│       ├── index.xhtml
│       ├── menu.xhtml
│       ├── next.xhtml
│       ├── parrot.xhtml
│       ├── template.xhtml
│       └── WEB-INF
│           └── web.xml
├── LICENSE
├── nbproject
│   ├── ant-deploy.xml
│   ├── build-impl.xml
│   ├── genfiles.properties
│   ├── private
│   │   └── private.properties
│   ├── project.properties
│   └── project.xml
├── README.md
└── src
    └── conf
        └── MANIFEST.MF
EAR如何构建:

facelet:

<!DOCTYPE    html  PUBLIC "-//W3C//DTD XHTML 1.0  Transitional//EN"  
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head></h:head>
    <h:body>
        This and everything before will be ignored
        <ui:composition template="template.xhtml">
            <ui:define name="navigation">
                <ui:include src="menu.xhtml"/>
            </ui:define>
            <ui:define name="main">
                <h1>bird</h1>
                next   #{myQueueBean.next}
            </ui:define>
        </ui:composition>
        This and everything after will be ignored
    </h:body>
</html>
完整资料来源:


你不应该把web前端工件放在业务/服务层后端。你能解释一下吗?也许我应该问一个不同的问题,他的意思是EJB不应该知道JSF管理的bean;情况恰恰相反。您试图将EJB和托管bean实现为同一类@Thufir?@kolossus有什么特别的原因吗?对不起,您指的是哪个类?我指的是MyQueueBean。为什么它被注释为EJB和JSF管理的bean?
<!DOCTYPE    html  PUBLIC "-//W3C//DTD XHTML 1.0  Transitional//EN"  
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head></h:head>
    <h:body>
        This and everything before will be ignored
        <ui:composition template="template.xhtml">
            <ui:define name="navigation">
                <ui:include src="menu.xhtml"/>
            </ui:define>
            <ui:define name="main">
                <h1>bird</h1>
                next   #{myQueueBean.next}
            </ui:define>
        </ui:composition>
        This and everything after will be ignored
    </h:body>
</html>
package dur.facelets;

import java.io.Serializable;
import java.util.logging.Logger;
import javax.inject.Named;
import javax.ejb.Singleton;
import javax.enterprise.context.ApplicationScoped;
//import javax.inject.Singleton;

@Named
@ApplicationScoped
@Singleton
public class MyQueueBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private final Logger log = Logger.getLogger(MyQueueBean.class.getName());
    private int next = 1001;

    public MyQueueBean() {
    }

    public int getNext() {
        log.info("next\t" + next);
        return next++;
    }
}