【发布时间】:2019-04-13 12:08:38
【问题描述】:
我正在尝试创建一个模式来将用户选择的请求发送到电子邮件地址;但是,我无法获取用户选择的请求。我不断得到通过fooBean.setSelected(id) 传递的空值。
版本:
- BootsFaces:1.3.0
- Java:1.8.0
- JSF:2.0
- 浏览器:Internet Explorer 11.2x
thisThing.xhtml 的 MCVE:
<b:dataTable value="#{fooBean.newRequests}"
var="foo"
onselect="ajax:fooBean.setSelected(id)"
ondeselect="ajax:fooBean.setSelected(id)"
selectedItems="row"
selection-mode="multiple"
selectedRows="#{foo.selected}"
saveState="false">
<b:dataTableColumn label="Select">
<b:selectBooleanCheckbox value="#{foo.selected}" />
</b:dataTableColumn>
<b:dataTableColumn label="Status" value="#{foo.status}" />
<b:dataTableColumn label="Request Number"
value="#{foo.requestNumber}"
data-type="string" />
<b:dataTableColumn label="ID" value="#{foo.id}" />
<b:dataTableColumn value="#{foo.storeName}"
label="Store Name" />
</b:dataTable>
fooBean.java 的 MCVE:
@ManagedBean(name="fooBean")
@ViewScoped
public class fooBean extends BeanBase implements Serializable {
private List<FooRecord> fooRecords = new ArrayList<FooRecord>();
private List<FooRecord> selectedFooRecords = new ArrayList<FooRecord>();
// ...
public void setSelected(String requestId) {
// This is not how I really do it, but it gives an idea
// with what I intend to do.
this.fooRecords.stream().filter(...).toggleSelection();
this.selectedFooRecords.stream().filter(...).toggleSelection();
}
}
更新:
我发现我的方法称为getSelect 而不是getSelected,所以我修复了它,这部分完成了。我只记得真正的问题,这就是为什么传递的是空参数而不是 requestId。当我通过fooBean.getSelected(String requestId) 进行调试时,它显示null 作为参数传递。我什至尝试过:
<!-- Using varName.property -->
onselect="ajax:fooBean.setSelected(foo.id)"
<!-- Using just the property name -->
onselect="ajax:fooBean.setSelected(id)"
<!-- Using the loop variable -->
onselect="ajax:fooBean.setSelected(foo)"
更新 2:
如何将foo.id 传递给函数?
【问题讨论】:
-
您使用的是什么版本的 BootsFaces?见showcase.bootsfaces.net/forms/DataTable.jsf#selectingServer
-
@JasperdeVries 1.3.0。用版本号更新问题并更新问题。
标签: jsf datatable bootsfaces