0

この場合、jDev を使用して DB に null/空の値を挿入し、アプリケーション モジュールを使用します。

これは bean のコードです:

public void insertM_LLOYDAGENT(ActionEvent actionEvent) {
    // Add event code here...
    UnderwritingAppModuleImpl am = (UnderwritingAppModuleImpl)ADFUtil.getApplicationModule("UnderwritingAppModuleDataControl");

    try{
        address = noteAddress.getValue().toString();
        city = noteCity.getValue().toString();
        contact = noteContact.getValue().toString();
        country = noteCountry.getValue().toString();
        name = noteName.getValue().toString();
        type = typeOfLloyd.getValue().toString();
        am.insertMLLOYDAGENT(address, city, contact, country, name, type);
    }
    catch(Exception ex){
        am.insertMLLOYDAGENT(address, city, contact, country, name, type);
    }
}

および AppModuleImpl のコード:

     public void insertMLLOYDAGENT(String noteAddress, String noteCity, String noteContact, String noteCountry, String noteName, String noteType){
    try {
        System.out.println("tes ------- address = "+noteAddress+" city = "+noteCity+" contact = "+noteContact+" country = "+noteCountry+" name = "+noteName+" type = "+noteType);
        MLloydagentViewImpl vo=(MLloydagentViewImpl)getMLloydagentView1();
        MLloydagentViewRowImpl row=(MLloydagentViewRowImpl)vo.getCurrentRow();
        row.setLloydName(noteName);
        row.setLloydAddress(noteAddress);
        row.setLloydCity(noteCity);
        row.setLloydContact(noteContact);
        row.setLloydCountry(noteCountry);
        row.setTypeOfLloyd(noteType);
        row.getDBTransaction().commit();
        vo.executeQuery();
    } catch (JboException ex) {
        throw ex;
    }
}

新しい行がコミットされないのはなぜですか? 私を助けてください。ありがとう !

4

1 に答える 1

2

投稿したコードは新しい行を挿入しませんが、現在の行がある場合は現在の行を更新します。

 MLloydagentViewRowImpl row=(MLloydagentViewRowImpl)vo.getCurrentRow();

新しい行を挿入するには、次のようなものを使用する必要があります

MLloydagentViewRowImpl row=(MLloydagentViewRowImpl)vo.createRow();
row.setLloydName(noteName);
...
vo.insertRow(row);
...

ただし、ここでフレームワークと戦っています。まず、最後のコミット以降に行ったすべての変更がコミットされるため、アプリケーション モジュールでトランザクションをコミットしないでください。このコードを別の場所で再利用すると、この時点でコミットしてはならない他の変更が含まれる可能性があります。次に、Bean 内でアプリケーション モジュールを使用しないでください。これは、モデル レイヤーのみを変更し、バインディング レイヤーを手動で (自分で) 更新する必要があるためです。ページで VO が使用されていると仮定すると、このビュー オブジェクトの反復子が pagedef ファイルに存在するはずです。その後、反復子バインディングにアクセスし、これを使用して新しい行を挿入する必要があります。このようにして、バインディング レイヤーは新しい行の情報を自動的に取得し、モデル レイヤーも更新されます。挿入後、コミット操作にバインドされた操作を取得して実行します。これにより、すべてのレイヤーで変更が保持されます。あなたは次のようなものになるはずです

public void xyz(ActionEvent actionEvent)
{
    // Get the data from an ADF tree or table
    DCBindingContainer dcBindings =
        (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
    // Get a attribute value of the current row of iterator
    DCIteratorBinding iterBind = (DCIteratorBinding) dcBindings.get("testIterator");
    RowSetIterator lIterator = iterBind.getRowSetIterator();
    MLloydagentViewRowImpl row = (MLloydagentViewRowImpl) lIterator.createRow();
    row.setLloydName(noteName);
    lIterator.insertRow(row);
    // now commit the action
    // get an Action or MethodAction
    OperationBinding method =
        BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding("Commit");
    method.execute();
    List errors = method.getErrors();
    if (!errors.isEmpty())
    {
        // an error occured so do something liek adding a mesage for the user
        Exception e = (Exception) errors.get(0);
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    // ok all is OK
}

さらに質問がある場合は、jdev のバージョンについて言及していただけると助かります。

ティモ

于 2012-07-19T10:43:03.073 に答える