我正在尝试在数据表上执行JSF / primefaces ajax更新,点击命令链接,我正在删除记录。点击命令链接我数据库得到了更新,但数据表不会刷新,即使我使用update =“@ form”属性。如何解决这个问题的任何指导都会非常有帮助。
我的JSF代码段,它是一个包含很少列的行可编辑数据表 像州,地区如下
<h:form id="lpcForm">
<div id="content">
<p:commandLink id="cmdLinkDelete" value="Delete" ajax="true"
action="#{lpcBean.deleteRecords}" update="lpcDataTable" />
<p:dataTable var="lpcData" id="lpcDataTable" widgetVar="lpcTable"
value="#{lpcBean.lpcIdList}" selection="#{lpcBean.selectedRows}"
editable="true" scrollable="true" scrollWidth="1110"
scrollHeight="330" styleClass="datatable" resizableColumns="true">
<p:ajax event="rowEdit" listener="#{lpcBean.onEdit}" />
<p:ajax event="rowEditCancel" listener="#{lpcBean.onCancel}" />
<p:column selectionMode="multiple" style="width:15px" />
<p:column headerText="LPC ID" style="width:20px">
<h:outputText value="#{lpcData.LPCID}" />
</p:column>
<p:column headerText="Region" style="width:40px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lpcData.region}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{lpcData.region}">
<f:selectItems value="#{lpcBean.regions}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="State" style="width:15px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lpcData.homeState}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{lpcData.homeState}">
<f:selectItems value="#{lpcBean.mainStates}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
.
.
.
<p:column style="width:10px">
<p:rowEditor />
</p:column>
</p:dataTable>
</div>
</h:form>
变量lpcIdList是实现 DataModel 的类的类型。
以下是包含 deleteRecords 方法的托管bean代码段。托管bean是 RequestScoped
public String deleteRecords()
{
System.out.println("inside delete records");
System.out.println("Selected rows length:"+ selectedRows.length);
for(LPC itemSelect:selectedRows)
{
String lpcId=itemSelect.getLPCID();
JdbcConnection jdbcConnection=new JdbcConnection();
connection=jdbcConnection.getJdbcConnection();
try{
preparedStmt=connection.prepareStatement("delete from LPC where LPCID=?");
preparedStmt.setString(1, lpcId);
preparedStmt.execute();
}
catch(Exception e)
{
e.printStackTrace();
}
}
return null;
}
变量 selectedRows 是数据表的选择属性
getLpcFields方法从数据库中提取数据
public void getLpcFields() {
try
{
JdbcConnection jdbcConnection =new JdbcConnection();
connection=jdbcConnection.getJdbcConnection();
System.out.println("connected to the database");
selectStmt1 = connection.createStatement();
ResultSet rs1 = selectStmt1.executeQuery("select * from LPC order by LPCID");
while(rs1.next()){
lpcItems.add(new LPC(rs1.getString("LPCID"),rs1.getString("Name_First"),rs1.getString("Name_Last"),rs1.getString("Email_Address"),rs1.getString("Region"),
rs1.getString("HomeState"),rs1.getString("ProfitCenter"),rs1.getString("Active_LPC"),rs1.getString("Name")));
}
selectStmt2=connection.createStatement();
ResultSet rs2=selectStmt2.executeQuery("Select * from Tbl_state");
while(rs2.next())
{
mainStates.add(rs2.getString("State"));
}
selectStmt3=connection.createStatement();
ResultSet rs3=selectStmt3.executeQuery("Select * from Tbl_Regional_Managers");
while(rs3.next())
{
regions.add(rs3.getString("Location"));
}
selectStmt4=connection.createStatement();
ResultSet rs4=selectStmt4.executeQuery("Select * from YesNo order by YesNo_Key desc");
while(rs4.next())
{
activeLpcs.add(rs4.getString("Description"));
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
Xtreme Biker的回答是正确的(h / t)。您需要清除lpcIdList中的包装数据。根据您实现代码的方式,您需要填充新列表或从现有列表中删除该项目。然后,您可以使用setWrappedData()
的{{1}}方法。