0

現在取り組んでいるプロジェクトに別の問題があります。これに対する解決策を見つけるためにあらゆる場所を検索しましたが、取得できませんでした...

私は id,firstName,lastName 属性を持つ Bean クラスを持っており、パブリックゲッターとセッター、および updateEmployee メソッドがあります。

次のjsfページを使用してデータベーステーブルの値を取得しています。

更新ボタンをクリックすると成功ページが表示されますが、データベースで値が変更されていません。データベースで値が変更されない理由を誰か教えてもらえますか?

JSF ページ:

<h:dataTable value="#{tableBean.employeeList}" var="employee" border="1">  
   <h:column>  
          <f:facet name="header">First name</f:facet>  
          <h:inputText value="#{employee.firstName}" />  
   </h:column>  

   <h:column>  
          <f:facet name="header">Last name</f:facet>  
          <h:inputText value="#{employee.lastName}" />  
   </h:column>  
</h:dataTable>  
<h:commandButton value = "update" action="#{employee.updateEmployee}"/> 

従業員.java:

public String updateEmployee(){  
   String query = "update employee set firstName = ?,lastName = ? where id = 1";           
   pstmt = conn.prepareStatement(query);  
   pstmt.setString(2,this.firstName);  
   pstmt.setString(3,this.lastName);   
   pstmt.executeUpdate(); // execute update statement  
   conn.commit();  
   committed = true;  
   return "success.xhtml";  
   }catch (Exception e) {  
       e.printStackTrace();  
       return null;  
   } finally {  
      try{  
         if (!committed) conn.rollback();  
              pstmt.close();  
          conn.close();  
       }catch(Exception e){  
            e.printStackTrace();  
      }  
    }  
 } 

ありがとう、ラーム

4

1 に答える 1

1

投稿されたコードは奇妙です。編集されたすべての従業員を保持している Bean でアクション メソッドを呼び出しているのではなく、代わりに、従業員の完全に空のインスタンスを表す Bean でアクション メソッドを呼び出しています。テーブル。

開始するには、交換してください

<h:commandButton value="update" action="#{employee.updateEmployee}" /> 

<h:commandButton value="update" action="#{tableBean.updateEmployees}" /> 

そしてそれはより簡単になります。

于 2012-10-19T02:32:41.167 に答える