在这种情况下,我将使用jDev和使用的应用程序模块向我的数据库插入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;
}
}
为什么新行没有提交? 请帮我。 谢谢!
答案 0 :(得分: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版本会有所帮助。
蒂莫