I have a managed bean called registerBean.
private List<registerBean> std;
public void onEdit(RowEditEvent event) {
registerBean ul = (registerBean) event.getObject();
Connection con = null;
PreparedStatement stat = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "");
stat = con.prepareStatement("update regtbl set fname=? where rno=?");
stat.setString(1, ul.fname);
stat.setInt(3, ul.rno);
stat.executeUpdate();
con.commit();
stat.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
This is my Facelets page
std.xhtml
<!-- language: xhtml -->
<p:dataTable value="#{registerBean.list}" var="rb" rows="10" paginator="true"
paginatorTemplate=" {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,15,20" rowKey="#{rb.fname}" selectionMode="single"
selection="#{registerBean.selectedStudent}"
scrollable="true" resizableColumns="true" editable="true" >
<p:ajax event="rowEdit" listener="#{registerBean.onEdit}"
update=":form:messages" />
<p:ajax event="rowEditCancel" listener="#{registerBean.onCancel}"
update=":form:messages" />
<p:column headerText="Roll No" filterBy="#{rb.rno}" sortBy="#{rb.rno}" width="124">
<h:outputText value="#{rb.rno}" />
</p:column>
<p:column headerText="First Name" filterBy="#{rb.fname}" sortBy="#{rb.fname}" width="124">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{rb.fname}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{rb.fname}" />
</f:facet>
</p:cellEditor>
</p:column>
<!-- more columns... -->
</p:dataTable>
我在这里的某些地方出错了吗.....调用此方法来保存已编辑的数据表行....但是数据库记录没有得到更新。当我在数据表中编辑特定行并单击右标记以保存更改时,正在调用 bean 内部的 onEdit 方法。问题是数据库值保持不变,没有更新列表是 registerBean 类型。在 registerBean 我正在执行其他操作,例如插入(工作正常),从数据库中获取显示在数据表中的值......在行编辑中面临问题。
Thanks in Advance Note: Check [this link][1]. My table is similar to this but i am using database. [1]: http://www.primefaces.org/showcase/ui/datatableEditing.jsf