从bean迭代数据 [英] Iterating through the datatable from the 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>
我要修改我的通知从datatable中的allNotifications列表中单击保存所有更改。如何从editCategoryBean遍历datatable?或者我如何实现这个行为?
I want to edit my notifications from the allNotifications List in the datatable and save all changes with one button click. How can I iterate through the datatable from the editCategoryBean? Or how can I implement this behaviour otherwise?
推荐答案
JSF已经更新了 value = #{editCategoryBean.allNotifications}
与提交的值通常的方式。所以你所需要做的就是把它传递给服务层来保存:
JSF has already updated the model behind value="#{editCategoryBean.allNotifications}"
with the submitted values the usual way. So, all you basically need to do is to pass it through to the service layer for save:
public void save() {
yourNotificationService.save(allNotifications);
}
否则,如果您真的坚持用某种原因自行迭代,打印所提交的值进行测试,然后只需通常使用Java方法:
Otherwise, if you really insist in iterating over it yourself for some reason, maybe to print the submitted values for testing purposes, then just do it the usual Java way:
public void save() {
for (Notification notification : allNotifications) {
System.out.println(notification.getKey());
System.out.println(notification.getLanguage());
System.out.println(notification.getValue());
}
}
这篇关于从bean迭代数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!