Other scenario is you may not have the access to the AM directly to which an entity belongs to. So, in that case you will not be able to use the VOs belonging to the AM for your requirements.
In such cases you can use the following code:
try{
FacesContext facesContext = FacesContext.getCurrentInstance();
ExpressionFactory exp = facesContext.getApplication().getExpressionFactory();
DCBindingContainer bindingContainer = (DCBindingContainer)exp.createValueExpression(facesContext.getELContext(),"#{bindings}",DCBindingContainer.class).getValue(facesContext.getELContext());
DCIteratorBinding itr = bindingContainer.findIteratorBinding("Dept1Iterator");
DemoAppAMImpl svc = (DemoAppAMImpl)itr.getDataControl().getApplicationModule();
PreparedStatement stmt = svc.getDBTransaction().createPreparedStatement("delete from dept_table",DBTransaction.DEFAULT);
stmt.execute();
svc.getDBTransaction().commit();
}catch(Exception e){}
This method in this case is written in a managed bean which is bound to a button on the ui. So, first thing that is done is getting the handle to ApplicationModule using iteratorBindings created for this purpose in the pageDef file.
Then getting the transaction and firing a sql using the transaction and finally commiting it.
No comments:
Post a Comment