0

在这种情况下,我将使用 jDev 和使用的应用程序模块将空/空值插入我的数据库。

这是 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 回答