Jsf 如何在EJB模块中调用支持bean
当我运行应用程序时,计数器按预期递增,但是如何将bean从web模块移动到ejb模块 一般结构: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
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++;
}
}