我正在使用primefaces来处理JSF,我在使用dataTable row Editing,其中包含来自数据库的数据,
问题
例如
JSF页面
<p:dataTable var="perreq" value="#{leaverequest.perRequestList}" id="perrequestlist" editable="true" >
<p:ajax event="rowEdit" update=":form0:form2:acivitydatatable,perrequestlist,:form0:form:growl" listener="#{leaverequest.onEdit}" />
<p:ajax event="rowEditCancel" listener="#{leaverequest.onCancel}" />
<p:column headerText="Name" style="width:100px;"><h:outputText value="#{perreq.ename}" /></p:column>
<p:column headerText="From" style="width:60px;"><h:outputText value="#{perreq.perFrom}" /></p:column>
<p:column headerText="To" style="width:60px;"><h:outputText value="#{perreq.perTo}"/></p:column>
<p:column headerText="Date" style="width:80px;">
<h:outputText value="#{perreq.dateOfPermission}" >
<f:convertDateTime pattern="dd-MM-yyyy" />
</h:outputText>
</p:column>
<p:column headerText="Reason" style="width:200px;"><h:outputText value="#{perreq.reason}" /></p:column>
<p:column headerText="Tl Comments" style="width:200px;"><h:outputText value="#{perreq.tlComments}" /></p:column>
<p:column headerText="Comments" style="width:160px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{leaverequest.perComments}" style="width:150px;" label="Year" maxlength="100"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Status" style="width:70px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{perreq.status}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{leaverequest.statusResult}" style="width:100px;" >
<f:selectItem itemLabel="Accept" itemValue="Accepted"/>
<f:selectItem itemLabel="Reject" itemValue="Rejected"/>
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column >
<p:column width="80px;"><p:rowEditor/></p:column>
</p:dataTable>
带有getter n setter的Bean:
public void onEdit(RowEditEvent event)
{
getPendingPermssionRequestDB();
}
public List<PendingRequestBean> getPerRequestList()
{
return perRequestList;
}
public void setPerRequestList(List<PendingRequestBean> perRequestList)
{
this.perRequestList = perRequestList;
}
public void getPendingPermssionRequestDB()
{
try
{
//Modify list and retrieve from DB
Session hibernateSession=HibernateUtil.getSessionFactory().openSession();
Query query=hibernateSession.createQuery("select a from Permissionrecord as a");
List<PendingRequestBean> l=(List<PendingRequestBean>)query.list();
this.perRequestList=l;
hibernateSession.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
任何建议......
答案 0 :(得分:0)
在编辑后点击行的复选标记时,会生成一个事件(我想你已经在使用它了)。只需调用一个侦听器方法,从表中删除表中的当前行并更新整个表:
<p:ajax event="rowEdit" listener="#{tableBean.onEdit}" update="table" />
这是您的托管bean的活动,上传tableElements
是包含dataTable
值的列表:
public void onEdit(RowEditEvent event) {
tableElements.remove((Element) event.getObject());
}
另见: