同じページ内のアイテムのリストを編集したいと考えています。各アイテムは、個別のフォームを使用して編集する必要があります。ui:repeat 内に ah:form を作成しています。最後のフォームが送信されたときにのみ、ユーザー入力がマネージド Bean に適用されます。他のすべてのフォームでは、ユーザー入力はモデルに適用されません。
@ManagedBean
public class Controller {
Logger logger = Logger.getLogger("TestWeb");
private List<Customer> customerList;
public List<Customer> getCustomerList() {
if (customerList == null) {
customerList = new ArrayList<Customer>();
customerList.add(new Customer("Daffy Duck", "daffy@example.com"));
customerList.add(new Customer("Bugs Bunny", "bugs@example.com"));
customerList.add(new Customer("Samity Sam", "sam@example.com"));
}
return customerList;
}
public String updateCustomer(Customer c) {
logger.info("Updating: " + c.getName());
return null;
}
}
ビューでは、私は持っています
<ui:repeat var="c" value="#{controller.customerList}">
<h:form>
<h3>Edit Customer</h3>
Name: <h:inputText value="#{c.name}"/><br/>
E-mail: <h:inputText value="#{c.email}"/><br/>
<h:commandButton value="Update"
action="#{controller.updateCustomer(c)}"/>
</h:form>
</ui:repeat>
何の解決策もなく何時間も探します。これを行う正しい方法は何ですか?単一のフォームを使用し、その中で ui:repeat を使用することでハッキングできます。しかし、それには多くの問題があり、私はむしろその道をたどりません。ありがとう。