是否可以使用事件?
在p:datatable中选择带有回车键的行?<p:dataTable value="#{bean.list}" var="l" selection="#{bean2.user}" rowKey="#{l}" selectionMode="single">
<p:ajax event="keyup" update="@form"/>
<p:column>
<h:outputText value="#{l.id}"/>
</p:column>
</p:dataTable>
答案 0 :(得分:0)
是的,你可以!请查看以下示例代码:
视图
<h:form id="mainForm">
<p:dataTable id="dt" value="#{rowSelectionBean.list}" var="item"
selectionMode="single" selection="#{rowSelectionBean.selectedRow}"
widgetVar="dtVar" rowKey="#{item.id}">
<p:column headerText="ID">
#{item.id}
</p:column>
<p:column headerText="Name">
#{item.name}
</p:column>
</p:dataTable>
<p:outputPanel id="display">
<h:outputText value="Selected row: #{rowSelectionBean.selectedRow.name}" rendered="#{not empty rowSelectionBean.selectedRow}" />
</p:outputPanel>
<p:hotkey bind="return" update="display" process="dt" />
</h:form>
The Bean
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class RowSelectionBean implements Serializable {
private List<SimpleBean> list;
private SimpleBean selectedRow;
@PostConstruct
public void setup() {
list = new ArrayList<SimpleBean>();
list.add(new SimpleBean(11, "A"));
list.add(new SimpleBean(22, "B"));
list.add(new SimpleBean(33, "C"));
}
public SimpleBean getSelectedRow() {
return selectedRow;
}
public void setSelectedRow(SimpleBean selectedRow) {
this.selectedRow = selectedRow;
}
public List<SimpleBean> getList() {
return list;
}
}