JSF 页面不从托管 bean 的字段中检索变量值
JSF page does not retrieve variable value from a managed bean's field
我有以下 JSF 页面。
"Manage Attendee" link 由以下 XHTML 定义:
<h:form>
<h:commandLink value="Manage Attendees" action="/Management/Event/manageAttendees?faces-redirect=true">
<f:setPropertyActionListener target="#{managerManager.currentEvent}" value="#{event}" />
</h:commandLink>
(...)
</h:form>
currentEvent 是 "ManagerManager" ManagedBean 中的一个字段,它在重定向时设置并引用描述字段中的事件。它有一个我们想要遍历的列表。然而,第二页:
不渲染属性。就像 currentEvent 列表是空的一样,调试报告说它不是。
以下是应该获得标题的第二页的代码:
<h2>Attendees in this Event</h2>
<h:dataTable
var="attendees"
summary="List of attendees in this event."
value="#{managerManager.currentEvent.attendees}"
rules="all"
cellpadding="5">
<h:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{attendees.attendee.name}" />
</h:column>
</h:dataTable>
ManagedBean 也是 session 范围的。看起来第二页没有访问 currentEvent... 为什么?
原来是导入语句错误。
托管 Bean 中使用的 @SessionScoped
注释来自
import javax.enterprise.context.SessionScoped;
而不是
import javax.faces.bean.SessionScoped;
显然应该如此。这解释了为什么只有这个特定页面在我的项目中有这个问题。
我有以下 JSF 页面。
"Manage Attendee" link 由以下 XHTML 定义:
<h:form>
<h:commandLink value="Manage Attendees" action="/Management/Event/manageAttendees?faces-redirect=true">
<f:setPropertyActionListener target="#{managerManager.currentEvent}" value="#{event}" />
</h:commandLink>
(...)
</h:form>
currentEvent 是 "ManagerManager" ManagedBean 中的一个字段,它在重定向时设置并引用描述字段中的事件。它有一个我们想要遍历的列表。然而,第二页:
不渲染属性。就像 currentEvent 列表是空的一样,调试报告说它不是。 以下是应该获得标题的第二页的代码:
<h2>Attendees in this Event</h2>
<h:dataTable
var="attendees"
summary="List of attendees in this event."
value="#{managerManager.currentEvent.attendees}"
rules="all"
cellpadding="5">
<h:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{attendees.attendee.name}" />
</h:column>
</h:dataTable>
ManagedBean 也是 session 范围的。看起来第二页没有访问 currentEvent... 为什么?
原来是导入语句错误。
托管 Bean 中使用的 @SessionScoped
注释来自
import javax.enterprise.context.SessionScoped;
而不是
import javax.faces.bean.SessionScoped;
显然应该如此。这解释了为什么只有这个特定页面在我的项目中有这个问题。