primefaces的删除功能出现的有关问题
primefaces的删除功能出现的问题
前端页面
<p:dataTable id="patchfiledatatable" var="patch" value="#{patchBean.files}" dynamic="true" emptyMessage="" paginator="true" rows="10" paginatorPosition="top">
<p:column >
<f:facet name="header">
<h:outputText value="删除" />
</f:facet>
<p:growl id="deleMeaage-dialog" showSummary="true" howDetail="true"/>
<p:commandLink id="delLink" action="#{patchBean.deletePatch}" update=":patchForm">
<f:setPropertyActionListener value="#{patch.path}" target="#{patchBean.delFilePath}" />
<h:outputText value="删除" />
</p:commandLink>
</p:column>
</p:dataTable>
后台代码
@ManagedBean(name = "patchBean")
@SessionScoped
public class TreeBean{
private List<PatchOutFile> files;
private String delFilePath;
public List<PatchOutFile> getFiles() {
return files;
}
public void setFiles(List<PatchOutFile> files) {
this.files = files;
}
public String getDelFilePath() {
return delFilePath;
}
public void setDelFilePath(String delFilePath) {
this.delFilePath = delFilePath;
}
//取得files内容(省略)
//删除不定文件
public void deletePatch(){
File delFile = new File(delFilePath);
FacesMessage msg = null;
try {
if(delFile.exists()){
boolean flag = delFile.delete();
System.out.println(flag);
if(flag){
files.clear();
this.getSubFiles(delFile.getParent());
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "删除成功", null);
}
}else{
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "该文件不存在", null);
}
FacesContext.getCurrentInstance().addMessage("patchForm:deleMeaage-dialog", msg);
} catch (Exception e) {
System.out.println("删除出现异常");
msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "操作失败", null);
FacesContext.getCurrentInstance().addMessage("patchForm:deleMeaage-dialog", msg);
e.printStackTrace();
}
}
}
前端页面
<p:dataTable id="patchfiledatatable" var="patch" value="#{patchBean.files}" dynamic="true" emptyMessage="" paginator="true" rows="10" paginatorPosition="top">
<p:column >
<f:facet name="header">
<h:outputText value="删除" />
</f:facet>
<p:growl id="deleMeaage-dialog" showSummary="true" howDetail="true"/>
<p:commandLink id="delLink" action="#{patchBean.deletePatch}" update=":patchForm">
<f:setPropertyActionListener value="#{patch.path}" target="#{patchBean.delFilePath}" />
<h:outputText value="删除" />
</p:commandLink>
</p:column>
</p:dataTable>
后台代码
@ManagedBean(name = "patchBean")
@SessionScoped
public class TreeBean{
private List<PatchOutFile> files;
private String delFilePath;
public List<PatchOutFile> getFiles() {
return files;
}
public void setFiles(List<PatchOutFile> files) {
this.files = files;
}
public String getDelFilePath() {
return delFilePath;
}
public void setDelFilePath(String delFilePath) {
this.delFilePath = delFilePath;
}
//取得files内容(省略)
//删除不定文件
public void deletePatch(){
File delFile = new File(delFilePath);
FacesMessage msg = null;
try {
if(delFile.exists()){
boolean flag = delFile.delete();
System.out.println(flag);
if(flag){
files.clear();
this.getSubFiles(delFile.getParent());
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "删除成功", null);
}
}else{
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "该文件不存在", null);
}
FacesContext.getCurrentInstance().addMessage("patchForm:deleMeaage-dialog", msg);
} catch (Exception e) {
System.out.println("删除出现异常");
msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "操作失败", null);
FacesContext.getCurrentInstance().addMessage("patchForm:deleMeaage-dialog", msg);
e.printStackTrace();
}
}
}