I think the title tells it all: I want to add a row to dataTable over AJAX. The datatable has input fields where user can put text. As simple as that, a pretty common case.
我认为标题说明了一切:我想在AJAX上添加一行到dataTable。datatable有输入字段,用户可以在其中放置文本。就这么简单,一个很常见的情况。
With session-scoped bean this no issue, as the same bean is updated over and over again. However, I want to do this in request scope. For each request, I guess I want to create a new bean and to populate it with the values from my form. Then I want my commandButton
's action
to add a new row, finally render the dataTable
over AJAX as usual.
对于会话范围内的bean,这没有问题,因为相同的bean会不断地更新。但是,我想在请求范围内执行此操作。对于每个请求,我想我要创建一个新的bean,并用表单中的值填充它。然后我希望我的命令按钮的动作添加一个新的行,最后像往常一样在AJAX上呈现dataTable。
The issue is that I don't know how to make JSF fill the newly-created request-bean with the current data from the dataTable component?
问题是,我不知道如何让JSF用来自dataTable组件的当前数据填充新创建的请求bean ?
There was a similar question asked and answered. However, that solution seems to reload the contents of the dataTable each time it is refreshed and manually inserts empty elements for the newly-inserted rows like this:
有一个类似的问题被问到和回答。但是,这个解决方案似乎每次刷新dataTable时都要重新加载它的内容,并为新插入的行手动插入空元素,如下所示:
// Preserve list with newly added items.
ror (int i = 0; i < (Integer) count.getValue(); i++) {
list.add(new Item());
}
To me, it seems that this approach also wipes the possible changes that the user did to rows (new and old)... if he doesn't first save them.
在我看来,这种方法似乎也消除了用户对行(新行和旧行)可能做的更改……如果他不先救他们。
Any pointers?
指针吗?
1 个解决方案
#1
3
You should really consider using the new JSF 2.0 view scope. This lies between the request and session scope in. This scope lives as long as you're interacting (submitting and navigating to) the same view. This is an exact suit for the particular functional requirement.
您应该考虑使用新的JSF 2.0视图范围。这介于请求和会话范围之间。只要您交互(提交和导航到)相同的视图,这个范围就会存在。这是针对特定功能需求的一套精确的套装。
See also
- CRUD in JSF 2.0
- 在JSF 2.0中杂质
- Benefits and pitfalls of
@ViewScoped
- @ViewScoped的好处和陷阱。
#1
3
You should really consider using the new JSF 2.0 view scope. This lies between the request and session scope in. This scope lives as long as you're interacting (submitting and navigating to) the same view. This is an exact suit for the particular functional requirement.
您应该考虑使用新的JSF 2.0视图范围。这介于请求和会话范围之间。只要您交互(提交和导航到)相同的视图,这个范围就会存在。这是针对特定功能需求的一套精确的套装。
See also
- CRUD in JSF 2.0
- 在JSF 2.0中杂质
- Benefits and pitfalls of
@ViewScoped
- @ViewScoped的好处和陷阱。