Jsf @命名为@products的getter无法通过bean发现模式识别;注「;
我正在尝试运行“使用WildFly开发JavaEE7”一书的示例。现在我面临以下问题: TheateInfo.java:Jsf @命名为@products的getter无法通过bean发现模式识别;注「;,jsf,cdi,producer,Jsf,Cdi,Producer,我正在尝试运行“使用WildFly开发JavaEE7”一书的示例。现在我面临以下问题: TheateInfo.java: @Model public class TheatreInfo { ... @Produces @Named public Collection<Seat> getSeats() { return Lists.newArrayList(seats); } ... } index.xhtml: <
@Model
public class TheatreInfo {
...
@Produces
@Named
public Collection<Seat> getSeats() {
return Lists.newArrayList(seats);
}
...
}
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>
只要我在我的beans.xml中使用bean discovery mode=“all”,这就非常有效——我在我的web浏览器中看到了一张座位表。当我在beans.xml中使用bean discovery mode=“annotated”时,我在浏览器中再也看不到座位表,我看到一个空表,但没有发生错误
在书中,他们使用bean discovery mode=“all”,但我更喜欢看哪些类是托管bean,哪些不是。要使用bean discovery mode=“annotated”,我必须将@Dependent添加到一些类中,但我无法用names producer方法解决这个问题。有人能帮忙吗?嗯,如果我使用
@Named
@RequestScoped
public class TheatreInfo {
...
代替
@Model
public class TheatreInfo {
...
不明白为什么@Model原型中包含@Named和@requestscope!?有人知道吗
谢谢,多米尼克读一下,也许对你有用。“在隐式归档中,CDI只能管理和注入带有作用域类型注释的bean。”感谢您的这篇文章。我认为我的问题在于我的生产者方法的返回类型是集合,我不能对它进行注释(第三方类),因此它不被认为是可注入bean!?
@Model
public class TheatreInfo {
...