2

我有两个 facelet 页面:customers.xhtml(带有客户列表)和 customer.xhtml,用于仅查看一位客户的详细信息。我在 customers.xhtml 中使用 ah:dataTable 组件:

<h:dataTable var="customer" value="#{customerBackingBean.customers}">...</h:dataTable>

现在我想为表中的每个客户创建一个超链接。超链接应导航到 customer.xhtml。每个客户都有一个属性primaryKey,它应该告诉 customer.xhtml 应该显示哪个客户。

我该怎么做呢?如果我为每个 facelet 页面使用两个不同的 backing-bean,它是如何工作的?

提前致谢。

4

2 回答 2

2
<h:commandLink action="customer.xhtml" ..>
    <f:setPropertyActionListener 
         target="#{customerBackingBean.currentCustomer}" 
         value="#{customer}" />
</h:commandLink>
  • 然后在 bean 中创建一个属性currentCustomer(使用 getter 和 setter)
  • #{customerBackingBean.currentCustomer}中的参考customer.xhtml

请注意范围 - 如果您使用重定向,您可能必须使用会话范围。

于 2010-02-16T14:53:26.983 回答
0

或者使用创建GET请求的常规超链接。

<h:outputLink value="customer.jsf">
    <f:param name="id" value="#{customer.id}" />
    <h:outputText value="#{customer.name}" />
</h:outputLink>

JSF 支持POST请求,但您仍然可以GET根据需要使用——这取决于您的需要以及页面是否需要可收藏。然后您需要在呈现客户页面时从 URL 中获取当前客户 ID。

请参阅如何使用 JSF 和导航规则创建带有参数的 GET 请求?

于 2010-02-16T15:01:05.683 回答