@Named @Produces getter 未被 bean-discovery-mode="annotated" 识别
@Named @Produces getter not recognized with bean-discovery-mode="annotated"
我正在尝试获取 "Java EE 7 Development with WildFly" 一书的样本 运行。现在我面临以下 question/problem:
TheatreInfo.java:
@Model
public class TheatreInfo {
...
@Produces
@Named
public Collection<Seat> getSeats() {
return Lists.newArrayList(seats);
}
...
}
Seat.java:
@Dependent
@Named
public class Seat {
...
public String getName() {
return name;
}
...
}
index.xhtml:
<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
template="/WEB-INF/templates/default.xhtml">
<ui:define name="content">
<h1>TicketBooker Machine</h1>
<h:form id="reg">
<h:panelGrid columns="1" border="1" styleClass="smoke">
<h:dataTable var="_seat" value="#{seats}" rendered="#{not empty seats}" styleClass="simpletablestyle">
...
</h:dataTable>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
beans.xml:
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all/annotated">
</beans>
这非常有效 - 我在我的网络浏览器中看到 table 个席位 - 只要我在我的 beans.xml 中使用 bean-discovery-mode="all"。一旦我在我的 beans.xml 中使用 bean-discovery-mode="annotated" 我就不再分别在我的浏览器中看到 table 个座位 我看到一个空的 table但没有发生错误。
在书中他们使用 bean-discovery-mode="all" 但我更喜欢看哪些 类 是托管 bean,哪些不是。要使用 bean-discovery-mode="annotated" 我必须将 @Dependent 添加到某些 类 但我无法使用 names producer 方法解决问题。有人可以帮忙吗?
嗯,如果我使用
它会运行
@Named
@RequestScoped
public class TheatreInfo {
...
而不是
@Model
public class TheatreInfo {
...
不明白为什么 @Named 和 @RequestScoped 包含在 @Model 构造型中!?有人知道吗?
谢谢,多米尼克
我正在尝试获取 "Java EE 7 Development with WildFly" 一书的样本 运行。现在我面临以下 question/problem:
TheatreInfo.java:
@Model
public class TheatreInfo {
...
@Produces
@Named
public Collection<Seat> getSeats() {
return Lists.newArrayList(seats);
}
...
}
Seat.java:
@Dependent
@Named
public class Seat {
...
public String getName() {
return name;
}
...
}
index.xhtml:
<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
template="/WEB-INF/templates/default.xhtml">
<ui:define name="content">
<h1>TicketBooker Machine</h1>
<h:form id="reg">
<h:panelGrid columns="1" border="1" styleClass="smoke">
<h:dataTable var="_seat" value="#{seats}" rendered="#{not empty seats}" styleClass="simpletablestyle">
...
</h:dataTable>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
beans.xml:
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all/annotated">
</beans>
这非常有效 - 我在我的网络浏览器中看到 table 个席位 - 只要我在我的 beans.xml 中使用 bean-discovery-mode="all"。一旦我在我的 beans.xml 中使用 bean-discovery-mode="annotated" 我就不再分别在我的浏览器中看到 table 个座位 我看到一个空的 table但没有发生错误。
在书中他们使用 bean-discovery-mode="all" 但我更喜欢看哪些 类 是托管 bean,哪些不是。要使用 bean-discovery-mode="annotated" 我必须将 @Dependent 添加到某些 类 但我无法使用 names producer 方法解决问题。有人可以帮忙吗?
嗯,如果我使用
它会运行@Named
@RequestScoped
public class TheatreInfo {
...
而不是
@Model
public class TheatreInfo {
...
不明白为什么 @Named 和 @RequestScoped 包含在 @Model 构造型中!?有人知道吗?
谢谢,多米尼克