<h:形式>在 <ui:repeat>不完全工作,只有最后一个 <h:form>被处理 [英] <h:form> within <ui:repeat> not entirely working, only the last <h:form> is processed

查看:23
本文介绍了<h:形式>在 <ui:repeat>不完全工作,只有最后一个 <h:form>被处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编辑同一页面中的项目列表.每个项目都应使用单独的表格进行编辑.我正在 ui:repeat 中创建一个 h:form.只有当最后一个表单被提交时,用户输入才会应用到托管 bean.对于所有其他表单,用户输入不会应用于模型.

I will like to edit a list of items in the same page. Each item should be edited using a separate form. I am creating a h:form within ui:repeat. Only when the last form is submitted, the user input is applied to the managed bean. For all other forms, user input is not applied to the model.

@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 来破解它.但是这有很多问题,我宁愿不走那条路.谢谢.

I search for hours without any solution. What will be the correct way to do this? I can hack it by using a single form and using a ui:repeat within it. But there are many issues with that and I will rather not take that route. Thanks.

推荐答案

这是 Mojarra 中 状态保存的错误.http://java.net/jira/browse/JAVASERVERFACES 中有几个类似的问题报告,其中包括 issue 2243.

This is a bug in state saving of <ui:repeat> in Mojarra. There are several similar issue reports at http://java.net/jira/browse/JAVASERVERFACES, among others issue 2243.

您基本上有 2 个选项:使用另一个迭代组件(例如 等),或用 MyFaces 替换 Mojarra(此结构中的 在那里).

You have basically 2 options: use another iterating component (e.g. <c:forEach>, <h:dataTable>, <t:dataList>, <p:dataList>, etc), or replace Mojarra by MyFaces (the <ui:repeat> in this construct works properly in there).

这篇关于&lt;h:形式&gt;在 &lt;ui:repeat&gt;不完全工作,只有最后一个 &lt;h:form&gt;被处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆