我有一个使用rowedit的p:datatable并且工作正常,但是当你删除一个没有更新的数据表时。
@Named(value = "localesMB")
@SessionScoped
public class LocalesMB implements Serializable {
/**
* Creates a new instance of Activos
*/
public LocalesMB() {
}
private List<entidades.Locales> localesAll = new ArrayList<>();
private entidades.Locales selected = new Locales();
public Locales getSelected() {
return selected;
}
public void setSelected(Locales selected) {
this.selected = selected;
}
public List<Locales> getLocalesAll() {
return localesAll;
}
public void setLocalesAll(List<Locales> localesAll) {
this.localesAll = localesAll;
}
public void deleteSelect(Locales locales) {
this.selected = locales;
}
public void obtenerLocalesAll() {
try {
FacesContext ctx1 = FacesContext.getCurrentInstance();
ValueExpression vex1 = ctx1.getApplication().getExpressionFactory().createValueExpression(ctx1.getELContext(), "#{controladorMB}", ControladorMB.class);
ControladorMB cn = (ControladorMB) vex1.getValue(ctx1.getELContext());
this.localesAll = cn.getInterfaces().obtenerLocalesAll();
} catch (Exception e) {
JsfUtil.addErrorMessage(e, "Error: obtenerActivosAll() " + e.getMessage());
}
}
public void eliminarLocal() {
try {
FacesContext ctx1 = FacesContext.getCurrentInstance();
ValueExpression vex1 = ctx1.getApplication().getExpressionFactory().createValueExpression(ctx1.getELContext(), "#{controladorMB}", ControladorMB.class);
ControladorMB cn = (ControladorMB) vex1.getValue(ctx1.getELContext());
cn.getInterfaces().eliminarLocal(this.selected);
this.localesAll = cn.getInterfaces().obtenerLocalesAll();
} catch (Exception e) {
JsfUtil.addErrorMessage(e, "Error: eliminarLocal() " + e.getMessage());
}
}
public void onRowEdit(RowEditEvent event) {
try {
Locales ps = (Locales) event.getObject();
FacesContext ctx1 = FacesContext.getCurrentInstance();
ValueExpression vex1 = ctx1.getApplication().getExpressionFactory().createValueExpression(ctx1.getELContext(), "#{controladorMB}", ControladorMB.class);
ControladorMB cn = (ControladorMB) vex1.getValue(ctx1.getELContext());
cn.getInterfaces().modificarLocal(ps);
this.localesAll = cn.getInterfaces().obtenerLocalesAll();
JsfUtil.addSuccessMessage("Se ha cambiado el valor correctamente.");
} catch (Exception e) {
JsfUtil.addErrorMessage(e, "Error: onRowEdit() " + e.getMessage());
}
}
}
XHTML
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./../resources/css/default.css" rel="stylesheet" type="text/css" />
<link href="./../resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
<title>Activos</title>
<script language="javascript">
window.onload = function() {
PF('tb1').clearFilters();
};
</script>
</h:head>
<h:body>
<h:form id="frm1">
<p:growl id="growl" sticky="true" showDetail="true"/>
<p:panel header="Locales e Instalaciones" id="pn1">
<p:dataTable emptyMessage="No se encontraron elementos" editable="true" rowKey="#{item.idLocales}"
id="tabla_listado" var="item" paginator="true" widgetVar="tb1"
rows="25" value="#{localesMB.localesAll}">
<f:facet name="header">
<h:outputText value="Locales e Instalaciones: #{localesMB.localesAll.size()}"/>
</f:facet>
<p:ajax event="rowEdit" listener="#{localesMB.onRowEdit}"/>
<p:column headerText="Descripción">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{item.descripcion}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{item.descripcion}" style="width:95%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Ubicación">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{item.ubicacion}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{item.ubicacion}" style="width:95%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:20px">
<p:rowEditor/>
</p:column>
<p:column style="width:20px">
<p:commandButton id="selectButton256" oncomplete="PF('confirmation').show()" process="@this, tabla_listado" actionListener="#{localesMB.deleteSelect(item)}"
icon="ui-icon-trash" title="Eliminar" update=":frm1:confirmDialog">
</p:commandButton>
</p:column>
</p:dataTable>
</p:panel>
<p:confirmDialog appendTo="@(body)" id="confirmDialog" message="Confirma que desea eliminar a: #{localesMB.selected.descripcion}"
header="Mensaje de Confirmación" severity="alert" widgetVar="confirmation" closeOnEscape="true">
<p:commandButton id="confirm" value="Sí" update=":frm1" oncomplete="PF('confirmation').hide()"
actionListener="#{localesMB.eliminarLocal}" process="@this" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>
<p:commandButton id="decline" value="No" onclick="PF('confirmation').hide()" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>
</p:confirmDialog>
</h:form>
答案 0 :(得分:0)
问题是,这段代码激活了过滤器,但是数据表没有filterValue:
<script language="javascript">
window.onload = function() {
PF('tb1').clearFilters();
};
</script>
DataTable frm1:tabla_listado已启用过滤但未定义filteredValue模型引用,以便向后兼容回退到页面viewstate方法以保持filteredValue。强烈建议使用filterValue模型引用过滤,因为不建议使用viewstate方法,将来会删除它。
解决方案:删除脚本。