我是Datatable的新生婴儿。我用roweditor。但问题是,值是在某些行中进行编辑后才显示。有时数据库也没有改变。我使用更新查询。任何人都可以帮助我吗?
提前完成。
here is my code:
public void onRowEdit(RowEditEvent event)
{
System.out.println("hello...");
detail_li.clear();
FacesMessage msg = new FacesMessage("row Edited",selected_bean.get_name());// i have doubt here
FacesContext.getCurrentInstance().addMessage(null, msg);
DBQuery db = new DBQuery();
String code=selected_bean.getCode();
String Student_name = selected_bean.getStudent_name();
System.out.println(" code$..."+code);
String Student_name = selected_bean.getStudent_name();
String rank = selected_bean.getRank();
String feedback = selected_sngbean.getFeedback();
int res = db.special_code(rank,feedback,code);//here used update query
detail_li = db.detaillist(class,code,student_name);
}
This is my datatable code..
<h:form id="for1">
<p:growl id="msgs2" showDetail="true"/>
<div>
<p:dataTable id="s" var="sn" value="#{songdet.song_li}" editable="true" style="font-size: 80%" selectionMode="single" selection="#{songdet.selected_sngbean}" rowKey="#{sn.track_no}" >
<p:ajax event="rowEdit" listener="#{home.onRowEdit(event)}" update="for1:msgs2" process="for1"/>
<p:ajax event="rowEditCancel" listener="#{home.onRowCancel(event)}" update=":for1:msgs2" process="for1"/>
<p:column headerText="Name" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.name}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{sn.name}" style="width:100%"/
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Age" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.age}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput2" value="#{sn.age}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="class" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.class}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput3" value="#{sn.class}" style="width:100%"/
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Rank" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.rank}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput55" value="#{sn.rank}" style="width:100%"/
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="feedback" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.feedback}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput6" value="#{sn.feedback}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:50px;height: 20px" >
<p:rowEditor />
</p:column>
<p:dataTable>
</div>
答案 0 :(得分:0)
public void onRowEdit(RowEditEvent event) {
int z;
System.out.println("the selected row is....."+table.getRowIndex());
z=table.getRowIndex();
check(z);
FacesMessage msg = new FacesMessage("Row Edited",check(z));
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public String check(int i){
String rank="";
String Feedback="";
String name="";
int q;
q=i;
sBean st=new sBean();
st=(sBean) student_list.get(q);
name=st.getname();
roll=st.getcode();
DBQuery db = new DBQuery();
int res = db.update(name,roll,rank);
return rank;
}