How to collect submitted values of a List in JSF?

前端 未结 1 1284
离开以前
离开以前 2021-01-19 14:22

I have a bean with a List:

@Named
@ViewScoped
public class Bean {

    private List items;
    private String value;

    @         


        
相关标签:
1条回答
  • 2021-01-19 14:57

    Your problem is caused because you're basically collecting all submitted values into one and same bean property. You need to move the value property into the bean behind var="item".

    <h:form>
        <ui:repeat value="#{bean.items}" var="item">
            <h:inputText value="#{item.value}" /> <!-- instead of #{bean.value} -->
        </ui:repeat>
        <h:commandButton action="#{bean.submit}" />
    </h:form>
    

    In the bean action method, simply iterate over items in order to get all submitted values via item.getValue().

    public void submit() {
        for (Item item : items) {
            System.out.println("Submitted value: " + item.getValue());
        }
    }
    
    0 讨论(0)
提交回复
热议问题