Reputation: 61
in this case i'll insert null/empty value to my DB with jDev and used application module..
this is the code in 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);
}
}
and the code in 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;
}
}
why the new row not commited? please help me. thanks !
Upvotes: 0
Views: 1737
Reputation: 2496
The code you posted does not insert a new row but updates the current row, if there is a current row.
MLloydagentViewRowImpl row=(MLloydagentViewRowImpl)vo.getCurrentRow();
to insert a new row you should use something like
MLloydagentViewRowImpl row=(MLloydagentViewRowImpl)vo.createRow();
row.setLloydName(noteName);
...
vo.insertRow(row);
...
However, you are fighting the framework here. First you should not commit the transaction in the application module as it commits all changes you made since the last commit. If you reuse this code somewhere else you might have other changes which should not committed at this point. Next you should not use the application module inside the bean, as this changes the model layer only and the binding layer needs to be refreshed by hand (by yourself). Assuming that you have the VO used on your page there should be an iterator for this view object present in the pagedef file. You should then access the iterator binding and use this to insert the new row. This way the binding layer gets knowledge of the new row automatically and the model layer is updated too. After the insert you get the operation binding to the commit operation and execute it. This will persist your changed in all layers. You'll should end up with something like
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
}
If you have further questions it would help if you mention your jdev version.
Timo
Upvotes: 2