Primefaces 字段更新按钮

Primefaces field update button

我有一个用于列出订单信息的简单 primefaces 页面

<?xml version="1.0" encoding="UTF-8"?>
<!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:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">

<h:head>
</h:head>
<h:body>
    <h3><h:outputText value="#{orderView.date.month}, #{orderView.date.dayOfMonth} #{orderView.date.year}"/></h3>
    <h:form>
        <c:forEach items="#{orderView.orders}" var="order">
            <p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true"/>
            <p:panel id="basic" header="Order ##{order.id} for #{order.customerName} from #{order.customerAddress}, #{order.date}"
                     footer="Total: #{order.totalPrice}" style="margin-bottom:20px">
                <h:panelGrid columns="2" cellpadding="10">
                    <c:forEach items="#{order.orderDetails}" var="detail">
                        <h:outputText value="#{detail.rowId}. #{detail.serialNumber} #{detail.amount} pcs"/>
                        <hr/>
                        <h:outputText value="#{itemView.getItemInfo(detail.serialNumber)}"/>
                        <hr/>
                    </c:forEach>
                </h:panelGrid>
            </p:panel>
        </c:forEach>
    </h:form>
</h:body>
</html>

我需要一个按钮来为整个列表更新这个字符串 <h:outputText value="#{itemView.getItemInfo(detail.serialNumber)}"/>。但由于它处于双 foreach 循环中,我如何管理将此字段分配给按钮操作?

尝试在输出文本中添加一种名为 observe-update 的样式,例如...

<h:outputText value="#{itemView.getItemInfo(detail.serialNumber)}" 
              styleClass="observe-update"/>

然后在您的 update="" 按钮中执行此操作...

<p:commandButton update="@(.observe-update)" ...

通过让 PF 搜索表达式找到所有匹配该样式的组件并更新它们,使用观察者模式是一个聪明的技巧。