Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jsf 2 - <h:form> within <ui:repeat> not entirely working, only the last <h:form> is processed

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", "[email protected]"));                          
            customerList.add(new Customer("Bugs Bunny", "[email protected]"));       
            customerList.add(new Customer("Samity Sam", "[email protected]"));
        }
        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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...