从bean遍历数据表



我有以下数据表:

   <h:form> 
<h:dataTable id = "notTable" value="#{editCategoryBean.allNotifications}" var="notification">
     <h:column>                 
        <f:facet name="header">Key</f:facet>                    
        <h:inputText id = "notkey" value="#{notification.key}" />
     </h:column>
     <h:column>
        <f:facet name="header">Lang</f:facet>
        <h:inputText id = "notlanguage" value="#{notification.language}"/>
     </h:column>
     <h:column>
        <f:facet name="header">Value</f:facet>
        <h:inputText id = "notvalue" value="#{notification.value}"/>      
     </h:column>
   </h:dataTable>
<h:commandButton action ="#{editCategoryBean.save()}"  value = "Save" >    </h:commandButton>

我想在数据表中编辑我的allNotifications列表中的通知,并通过单击一个按钮保存所有更改。我如何从editCategoryBean迭代数据表?或者我如何实现这个行为?

JSF已经按照通常的方式用提交的值更新了value="#{editCategoryBean.allNotifications}"背后的模型。所以,你所需要做的就是把它传递给服务层save:

public void save() {
    yourNotificationService.save(allNotifications);
}

否则,如果出于某种原因,您真的坚持要自己迭代它,可能是为了打印提交的值以进行测试,那么就按照通常的Java方式执行:

public void save() {
    for (Notification notification : allNotifications) {
        System.out.println(notification.getKey());
        System.out.println(notification.getLanguage());
        System.out.println(notification.getValue());
    }
}

最新更新