ADF : ViewObject, Session, FacesMessage, Datasource, addScript
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;
import oracle.jbo.ApplicationModule;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.naming.InitialContext;
#######################Get Session###############################
HttpServletRequest request =
(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession httpSession = request.getSession(true);
######################Get BindingContainer################################
public BindingContainer getBindings() {
return BindingContext.getCurrent().getCurrentBindingsEntry();
}
########################Get ViewObject From Iterator##############################
public void executeVOQuery(){
DCBindingContainer bc = (DCBindingContainer)this.getBindings();
DCIteratorBinding dcIbbLink = bc.findIteratorBinding("Header_InputEOUPVO1Iterator");
//to get viewobject
ViewObject header_InputEOUPVO = dcIbbLink.getViewObject();
//to get all rows
Row[] headerRows = dcIbbLink.getAllRowsInRange();
header_InputEOUPVO.setWhereClause("REFERENCE_ID = "+referenceIdEntered_Int);
header_InputEOUPVO.setWhereClause("AND SIZING_CODE in (select distinct body_material from xxcz_dmc_pa_usm_conn where model_name = '"+modelSelected+"')");
header_InputEOUPVO.executeQuery();
}
########################Get ViewObject From ApplicationModule##############################
public void getVOFromAM(){
BindingContext bctx = BindingContext.getCurrent();
DCDataControl dc = bctx.findDataControl("AppModuleDataControl");
ApplicationModule service = (ApplicationModule)dc.getDataProvider();
System.out.println("service : "+service);
ApplicationModule am = service.findApplicationModule("AppModule");
System.out.println("am : "+am);
ViewObject modelResultVO = am.findViewObject("Model_Result_ROVO2");
}
########################get All Rows from ViewObject##############################
public void getAllRowRangeFromVO(){
DCBindingContainer bc = (DCBindingContainer)this.getBindings();
Row ProcessFluidType[] = bc.findIteratorBinding("ProcessFluidTypeROVO1Iterator").getAllRowsInRange();
System.out.println(" ************************************* : "+ProcessFluidType);
if(ProcessFluidType != null){
for(int i=0; i< ProcessFluidType.length; i++){
System.out.println(" row "+ProcessFluidType.length);
Row rowMatch = ProcessFluidType[i];
System.out.println(" rowMatch ProcessFluidType************ : "+rowMatch);
if(rowMatch != null){
System.out.println(" rowMatch.getAttribute(\"PfluidtypeCode\") : "+rowMatch.getAttribute("PfluidtypeCode")+ "and final_ProcessFluidType : "+final_ProcessFluidType);
if(rowMatch.getAttribute("PfluidtypeCode").toString().equalsIgnoreCase(final_ProcessFluidType)){
System.out.println(" *********** : "+i);
bc.findIteratorBinding("ProcessFluidTypeROVO1Iterator").setCurrentRowIndexInRange(i);
if(i==0) {
getEnterName().setDisabled(true);
getSoc1().setDisabled(false);
}
break;
}
}
}
}
}
########################Execute operationBinding##############################
public String executeCommitForProcess_InputVO(){
System.out.println("Inside executeCommitForProcess_InputVO ........//////////////////////////////////////////////////////...............................");
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("Commit1");
System.out.println("Going to execute Commit1111111111111, For Process Input VOOOOOOOOOOOOOOOOOOOOOO. ");
Object result = operationBinding.execute();
System.out.println("Executed Commit1111111111111 For Process Input VOOOOO : ");
if (!operationBinding.getErrors().isEmpty()) {
System.out.println("Binding Error");
return null;
}
System.out.println("Inside executeCommitForProcess_InputVO ........///////////////////////////.............");
return null;
}
########################ADF Error Message##############################
public void setErrorMessageForParticularComponent()
{
FacesContext fc = FacesContext.getCurrentInstance();
UIComponent uIComponent;
uIComponent = spGravity;
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Invalid Specific Gravity",
"Please provide Specific Gravity, Example: 10.2");
fc.addMessage(uIComponent.getClientId(fc), message);
((RichInputText)uIComponent).setValid(false);
}
########################resolveExpression##############################
public static Object resolveExpression(String expression) {
FacesContext facesContext = FacesContext.getCurrentInstance();
javax.faces.application.Application app =
facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp =
elFactory.createValueExpression(elContext, expression,
Object.class);
return valueExp.getValue(elContext);
}
########################Datasource Connection##############################
public Connection getConnectionFromDatasource() {
System.out.println("---------------------------------> Inside getConnectionFromDatasource");
ResourceBundle rb=ResourceBundle.getBundle("PropertyFile");
String datasource_name = rb.getString("DATASOURCE_NAME");
Connection connection = null;
try{
Context ic = new InitialContext();
javax.sql.DataSource dataSource = (javax.sql.DataSource) ic.lookup(datasource_name);
connection = dataSource.getConnection();
}
catch(Exception e){
//e.printStackTrace();
System.out.println("Exception : "+e.getMessage());
}
System.out.println("---------------------------------> completed getConnectionFromDatasource");
return connection;
}
########################CloseWindow Javascript in bean##############################
public String closeWindow() {
FacesContext facesContext = FacesContext.getCurrentInstance();
org.apache.myfaces.trinidad.render.ExtendedRenderKitService service =
org.apache.myfaces.trinidad.util.Service.getRenderKitService(facesContext,
ExtendedRenderKitService.class);
//service.addScript(facesContext,
// "window.close();window.opener.location.href = window.opener.location.href;");
service.addScript(facesContext,
"window.close();");
return null;
}
########################show popup Javascript in bean##############################
public String displaySavedSucessfullMessagePopup(HashMap refInfo_HM) {
System.out.println("Inside displayFluidListPopup ...................................................");
FacesContext context = FacesContext.getCurrentInstance();
StringBuilder script = new StringBuilder();
script.append("var popup = AdfPage.PAGE.findComponent('p4'); ");
script.append("if (!popup.isPopupVisible()) { ").append("popup.show();}");
ExtendedRenderKitService erks =
Service.getService(context.getRenderKit(),
ExtendedRenderKitService.class);
erks.addScript(context, script.toString());
System.out.println("Completed displayFluidListPopup ...................................................");
return null;
}