嗨社区我在primefaces 5的数据表中有一个单选按钮选择查询,当我点击注册并调用要编辑的事件时,不捕获注册表值会返回null对象。
我的代码xhtml:
<p:dataTable id="tblProductos" var="producto"
value="#{cBusquedaProducto.lazyDataProductos}"
rowIndexVar="rowIndex" lazy="true" rows="10"
paginator="true" paginatorPosition="top"
rowKey="#{producto.icodProducto}"
selectionMode="single"
selection="#{cBusquedaProducto.producto}"
emptyMessage="#{msg['tabla.noExistenRegistros']}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="Registros: {totalRecords} - [ {currentPage} de {totalPages} ]"
rowsPerPageTemplate="10,20,30,40,50,200">
<p:column selectionMode="single" />
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="#{msg['form.item']}" />
</f:facet>
<h:outputText value="#{rowIndex + 1}" />
</p:column>
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="#{msg['form.codigo']}" />
</f:facet>
<h:outputText value="#{producto.icodProducto}" />
</p:column>
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="#{msg['form.descripcion']}" />
</f:facet>
<h:outputText value="#{producto.vdesProducto}" />
</p:column>
.......
</p:dataTable>
控制器:
@ManagedBean(name = "cBusquedaProducto")
@ViewScoped
public class CBusquedaProducto extends BaseController {
@ManagedProperty(value = "#{iProductoService}")
private IProductoService iProductoService;
private LazyDataModel<ProductoBean> lazyDataProductos;
@PostConstruct
@Override
public void inicializarObjetos() {
try {
/* Cargamos las listas */
Map<String, Serializable> filters = new HashMap<String, Serializable>();
filters.put("param.icodEmpresa", Constantes.ONE_INT);
this.lazyDataProductos = new ProductoLazyDataModel(iProductoService, filters);
this.opcProducto = Constantes.ONE_SHORT;
} catch (Exception e) {
LOGGER.error(getGenerarError(
Thread.currentThread().getStackTrace()[1].getMethodName(),
Constantes.NIVEL_APP_CONSTROLLER,
this.getClass().getName(), e.getMessage()));
}
}
... get and set
}
LazyDataModel:
public class ProductoLazyDataModel extends LazyDataModel<ProductoBean> {
private static final long serialVersionUID = 1L;
public Logger logger = LoggerFactory.getLogger(this.getClass());
private List<ProductoBean> datasource;
Map<String, Serializable> extFilters = new HashMap<String, Serializable>();
private int pageSize;
private int rowIndex;
private int rowCount;
private IProductoService iProductoService;
/**
* @param iProductoService - El servicio para obtener datos desde base de datos.
* @param extFilters - Los filtros a aplicar a las columnas, acepta nulo.
*/
public ProductoLazyDataModel(IProductoService iProductoService,
Map<String, Serializable> extFilters) {
this.iProductoService = iProductoService;
this.extFilters = extFilters;
}
@Override
public List<ProductoBean> load(int first, int pageSize, String sortField,
SortOrder sortOrder, Map<String, Object> filters) {
try {
SortCriteria sort = new SortCriteria();
if (sortField == null) {
sort.add("icodProducto", false);
} else {
if (sortOrder == SortOrder.ASCENDING) {
sort.add(sortField, true);
} else {
sort.add(sortField, false);
}
}
WrappedData<ProductoBean> wd = iProductoService.obtenerProductos(filters,
extFilters, sort, first, pageSize);
datasource = wd.getData();
setRowCount(wd.getRowCount().intValue());
} catch (Exception e) {
logger.error(e.toString());
}
return datasource;
}
@Override
public boolean isRowAvailable() {
if (datasource == null)
return false;
int index = rowIndex % pageSize;
return index >= 0 && index < datasource.size();
}
@Override
public Object getRowKey(ProductoBean gr) {
return gr.getIcodProducto();
}
@Override
public ProductoBean getRowData() {
if (datasource == null)
return null;
int index = rowIndex % pageSize;
if (index > datasource.size()) {
return null;
}
return datasource.get(index);
}
@Override
public ProductoBean getRowData(String rowKey) {
if (datasource == null)
return null;
for (ProductoBean gr : datasource) {
String cod = String.valueOf(gr.getIcodProducto());
if (cod.equals(rowKey)) {
return gr;
}
}
return null;
}
@Override
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
@Override
public int getPageSize() {
return pageSize;
}
@Override
public int getRowIndex() {
return this.rowIndex;
}
@Override
public void setRowIndex(int rowIndex) {
this.rowIndex = rowIndex;
}
@Override
public void setRowCount(int rowCount) {
this.rowCount = rowCount;
}
@Override
public int getRowCount() {
return this.rowCount;
}
@SuppressWarnings("unchecked")
@Override
public void setWrappedData(Object list) {
this.datasource = (List<ProductoBean>) list;
}
@Override
public Object getWrappedData() {
return datasource;
}
}
希望你能帮助我,因为我找到了原因,我已经尝试过chekbox,如果它有效,但是无线电按钮无效......