从UI dataTable编辑单元格后无法更新我的数据库表

时间:2016-03-15 10:30:16

标签: java jsf jdbc

这是我的java代码,用于更新数据库表和从UI编辑单元格。

从用于标题列的UI编辑其精细但不更新数据库表中的列值。

public void onCellEdit(CellEditEvent event) {
    System.out.println("inside cell edit");

     UIColumn col=(UIColumn) event.getColumn();
    DataTable o = (DataTable) event.getSource();
    Object oldValue = event.getOldValue();
    Object newValue = event.getNewValue();
    LabelsVO info = (LabelsVO) o.getRowData();
    int newModel = info.getLang_no();
    int newData=info.getLabel_no();

    System.out.println("row index in event method " + event.getRowIndex());
    System.out.println("old value" + oldValue);
    System.out.println("new value" + newValue);
    System.out.println("column1 :" + col.getHeader());

    try {
        conn=Database.getConnection();
        stmt = conn.prepareStatement("update ias_labels set caption_det =? where lang_no =? and label_no=?");
        stmt.setInt(1, newModel);
        stmt.setInt(2, newData);
        stmt.setString(3, newValue.toString());
        int rset = stmt.executeUpdate();
        conn.commit();
        if (rset != 0) {
            System.out.println("updated!!!");
        } else {
            System.out.println("not updated!!!");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    if (newValue != null && !newValue.equals(oldValue)) {
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

这是我的前端课程

<p:layoutUnit position="center" resizable="true" closable="true" collapsible="true">
                    <p:dataTable id="dataTable" var="lab" value="#{labelsMB.userLogList}" editable="true" editMode="cell"  
                                 paginator="true" rows="10"  
                                 paginatorTemplate="  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15">  
                        <f:facet name="header">  
                            Labels Details
                        </f:facet>
                        <p:ajax event="cellEdit" immediate="true" listener="#{labelsMB.onCellEdit}" update="dataTable" />

                        <p:column headerText="Caption" sortBy="#{lab.caption_det}" filterBy="#{lab.caption_det}" width="40">  
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{lab.caption_det}"/>
                                </f:facet>
                                <f:facet name="input">
                                    <h:inputText value="#{lab.caption_det}" style="width:96%"/>
                                </f:facet>
                            </p:cellEditor>
                            </p:column>

                        <p:column sortBy="#{lab.label_no}" filterBy="#{lab.label_no}" width="10">  
                            <f:facet name="header">  
                                <h:outputText value="Label No" />  
                            </f:facet>  
                            <h:outputText value="#{lab.label_no}" />  
                        </p:column>  
                        <p:column sortBy="#{lab.lang_no}" filterBy="#{lab.lang_no}" width="10">  
                            <f:facet name="header">  
                                <h:outputText value="Langauge No" />  
                            </f:facet>  
                            <h:outputText value="#{lab.lang_no}" /> 
                        </p:column> 
                        <p:column sortBy="#{lab.lang_name}" filterBy="#{lab.lang_name}" width="10">  
                            <f:facet name="header">  
                                <h:outputText value="Langauge Name" />  
                            </f:facet>  
                            <h:outputText value="#{lab.lang_name}" /> 
                        </p:column> 
                        <f:facet name="footer">
                            <p:commandButton id="dataTable" icon="ui-icon-disk" iconPos="left" ajax="false" value="Save" action="#{labelsMB.onCellEdit(event)}" />
                        </f:facet>
                    </p:dataTable>  

0 个答案:

没有答案