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

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

问题描述

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

  @ManagedBean 
公共类控制器{
Logger logger = Logger.getLogger(TestWeb);
私人列表< Customer> customerList;

公共列表< Customer> getCustomerList(){
if(customerList == null){
customerList = new ArrayList< Customer>();
customerList.add(新客户(Daffy Duck,daffy@example.com));
customerList.add(新客户(Bugs Bunny,bugs@example.com));
customerList.add(新客户(Samity Sam,sam@example.com));
}
返回customerList;

public String updateCustomer(Customer c){
logger.info(Updating:+ c.getName());
返回null;


$ / code $ / pre

在视图中我有$ / $>

 < ui:repeat var =cvalue =#{controller.customerList}> 
< h:form>
< h3>编辑客户< / h3>
名称:< h:inputText value =#{c.name}/>< br />
电子邮件:< h:inputText value =#{c.email}/>< br />
< h:commandButton value =Update
action =#{controller.updateCustomer(c)}/>
< / h:表格>
< / ui:repeat>

我在没有任何解决方案的情况下搜索小时。什么才是正确的方法来做到这一点?我可以通过使用单个表单并使用ui进行破解:在其中重复。但是有很多问题,我宁愿不采取这样的路线。感谢。

解决方案

这是状态保存< ui:repeat> 在莫哈拉。在 http://java.net/jira/browse/JAVASERVERFACES 上有几个类似的问题报告,其中 issue 2243

基本上有两个选项:使用另一个迭代组件(例如< c:forEach> < h:dataTable> < ; t:dataList> < p:dataList> 等),或者用MyFaces替换Mojarra(< ; ui:repeat> 在这个构造中可以正常工作)。


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;
    }
}

In the view, I have

<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>

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.

解决方案

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.

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; within&lt; ui:repeat&gt;不完全工作,只有最后&lt; h:form&gt;被处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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