2012-07-19 85 views
0

在這種情況下,我會插入空/空值到我的分貝的jdev和使用的應用程序模塊..爲什麼我不能在jDeveloper adf中插入空值?

這是豆代碼:

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; 
    } 
} 

爲什麼新行沒有提交? 請幫助我。 謝謝!

回答

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版本,它會有所幫助。

Timo

+0

感謝您的關注Timo。首先,我是jdev的新手..所以我真的與框架混淆。 但是,爲什麼我不能插入行的空值? – anombhayu 2012-07-20 02:16:45

+0

我認爲promblem是TypeOfLloyd引用其他表的屬性,我總是嘗試在這個屬性上輸入null值。哈哈哈。這是我的錯。對不起蒂莫 – anombhayu 2012-07-20 02:51:27

+0

那麼你的問題是回答呢? – 2012-07-20 09:59:38

相關問題