Hello All
Hope Everyone knows about list of values and autoSuggest beahvior of ADF Framework,
For those who are new to framework can look at this post
ADF Basics : Implementing auto suggest behavior in ADF Faces lov (list of values)
Blog about Oracle ADF, JDeveloper, PL/SQL, Java, JavaScript, jQuery and Other Web Technologies
<af:outputText value="Page 1" id="ot1" inlineStyle="font-size:medium;font-weight:bold;"/> <af:commandButton text="Go To Second Page" id="cb1" action="forward"/>
<af:outputText value="Page 2" id="ot1" inlineStyle="font-size:medium;font-weight:bold;"/> <af:commandButton text="Go To First Page" id="cb1" action="backward"/>
function preventBackButton() { window.history.forward(); }
<af:clientListener method="preventBackButton" type="load"/>
/** * @return the associated entity oracle.jbo.RowIterator. */ public RowIterator getEmployeesEO1() { return (RowIterator)getAttributeInternal(EMPLOYEESEO1); }
/** * Add entity remove logic in this method. */ public void remove() { //Get all Employees of currenlty selected Department RowIterator employees = getEmployeesEO1(); while (employees.hasNext()) { //Delete all Employees employees.next().remove(); } //Delete Department itself after deleting all Employees associated with it super.remove(); }
/**ValueChangeListener for SelectManyChoice (Executes Javascript to replace 'All' text) * @param vce */ public void selectManyVCE(ValueChangeEvent vce) { //String to store all selected Departments Name String displayVal = ""; //Get BindingContainer of current page BindingContext bctx = BindingContext.getCurrent(); BindingContainer bindings = bctx.getCurrentBindingsEntry(); //Get Iterator of SelectManyChoice DCIteratorBinding iter = (DCIteratorBinding) bindings.get("Departments1Iterator"); if (vce.getNewValue() != null) { //Get all selected values in an Object array Object[] selectedVals = (Object[]) vce.getNewValue(); //Iterate over array to get all selected DepartmentId for (int i = 0; i < selectedVals.length; i++) { Integer val = (Integer) selectedVals[i]; //Create Key using DepartmentId to use furhter Key key = new Key(new Object[] { val }); //Get ViewObject row using Key vlaue Row row = iter.getViewObject().getRow(key); // Get DepartmentName from row and add it to String if (displayVal != "") { displayVal = displayVal.concat(", ").concat(row.getAttribute("DepartmentName").toString()); } else { displayVal = displayVal.concat(row.getAttribute("DepartmentName").toString()); } } //Write JavaScript code to change text of selectManyChoice as a StingBuilder Object StringBuilder jsString = new StringBuilder(); //First Step-get clientID of component jsString.append("var elementId = '" + vce.getComponent().getClientId()); //Second- add ::content to access it's value jsString.append("::content';"); //Third- Check that current value is 'All' or not jsString.append("\n if (document.getElementById(elementId).value == 'All') {"); //Forth- if yes then assign Department Name's string as value of selectManyChoice jsString.append("\n document.getElementById(elementId).value ='" + displayVal + "' \n};"); System.out.println("JS File-" + jsString); //Call this JavaScript code using this Helper method writeJavaScriptToClient(jsString.toString()); } }
/**Helper Method to call Javascript * @param javascriptCode */ public static void writeJavaScriptToClient(String javascriptCode) { FacesContext facesCtx = FacesContext.getCurrentInstance(); ExtendedRenderKitService service = Service.getRenderKitService(facesCtx, ExtendedRenderKitService.class); service.addScript(facesCtx, javascriptCode); }
import javax.faces.context.FacesContext; import javax.faces.event.ValueChangeEvent; import oracle.adf.model.BindingContext; import oracle.adf.model.binding.DCIteratorBinding; import oracle.binding.BindingContainer; import oracle.jbo.Key; import oracle.jbo.Row; import org.apache.myfaces.trinidad.render.ExtendedRenderKitService; import org.apache.myfaces.trinidad.util.Service;
/**Custom QueryOperationListener that hadles variois events raised by af:query * @param queryOperationEvent */ public void deptSeacrhQueryOperationList(QueryOperationEvent queryOperationEvent) { //Invoke default operation listener invokeEL("#{bindings.DepartmentsVOCriteriaQuery.processQueryOperation}", Object.class, QueryOperationEvent.class, queryOperationEvent); System.out.println("Query Event is-" + queryOperationEvent.getOperation().name()); //Check that current operation is RESET if (queryOperationEvent.getOperation().name().equalsIgnoreCase("RESET")) { DCIteratorBinding iter = (DCIteratorBinding) getBindings().get("Departments1Iterator"); ViewObjectImpl vo = (ViewObjectImpl) iter.getViewObject(); // Setting the value of bind variable vo.ensureVariableManager().setVariableValue("BindDeptNm", "Human Resource"); } }
/** * @param expr * @param returnType * @param argTypes * @param args * @return */ public Object invokeMethodExpression(String expr, Class returnType, Class[] argTypes, Object[] args) { FacesContext fc = FacesContext.getCurrentInstance(); ELContext elctx = fc.getELContext(); ExpressionFactory elFactory = fc.getApplication().getExpressionFactory(); MethodExpression methodExpr = elFactory.createMethodExpression(elctx, expr, returnType, argTypes); return methodExpr.invoke(elctx, args); } /** * @param expr * @param returnType * @param argType * @param argument * @return */ public Object invokeEL(String expr, Class returnType, Class argType, Object argument) { return invokeMethodExpression(expr, returnType, new Class[] { argType }, new Object[] { argument }); }
//Binding of af:query in managed bean private RichQuery queryPanelDept; public void setQueryPanelDept(RichQuery queryPanelDept) { this.queryPanelDept = queryPanelDept; } public RichQuery getQueryPanelDept() { return queryPanelDept; }
private String current_mode = "B"; /**Method Action to change mode of af:query * @param actionEvent */ public void changeModeAction(ActionEvent actionEvent) { if (current_mode == "B") { getQueryPanelDept().getValue().changeMode(QueryDescriptor.QueryMode.ADVANCED); current_mode = "A"; } else if (current_mode == "A") { getQueryPanelDept().getValue().changeMode(QueryDescriptor.QueryMode.BASIC); current_mode = "B"; } }
/**Method to invoke EL Expression * @param el * @param paramTypes * @param params * @return */ public static Object invokeEL(String el, Class[] paramTypes, Object[] params) { FacesContext facesContext = FacesContext.getCurrentInstance(); ELContext elContext = facesContext.getELContext(); ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory(); MethodExpression exp = expressionFactory.createMethodExpression(elContext, el, Object.class, paramTypes); return exp.invoke(elContext, params); } /**Method to get Binding Container of current page * @return */ public BindingContainer getBindings() { return BindingContext.getCurrent().getCurrentBindingsEntry(); }
/**Custome Query Listener- Using getNamedWhereClauseParam * @param queryEvent */ public void customQueryListener(QueryEvent queryEvent) { String deptName = null; Integer locId = null; Integer mgrId = null; /**Get Iterator of Table*/ DCIteratorBinding iter = (DCIteratorBinding)getBindings().get("DepartmentsView1Iterator"); /**Get ViewObject from Iterator*/ ViewObjectImpl vo = (ViewObjectImpl)iter.getViewObject(); /**Get Bind Variable's Value*/ if (vo.getNamedWhereClauseParam("LocIdBind") != null) { locId = Integer.parseInt(vo.getNamedWhereClauseParam("LocIdBind").toString()); } if (vo.getNamedWhereClauseParam("MgrIdBind") != null) { mgrId = Integer.parseInt(vo.getNamedWhereClauseParam("MgrIdBind").toString()); } if (vo.getNamedWhereClauseParam("DeptNmBind") != null) { deptName = vo.getNamedWhereClauseParam("DeptNmBind").toString(); } /**Check for Negative values*/ if ((locId != null && locId < 0) || (mgrId != null && mgrId < 0)) { FacesMessage msg = new FacesMessage("Id Value can not be negative"); msg.setSeverity(FacesMessage.SEVERITY_ERROR); FacesContext.getCurrentInstance().addMessage(null, msg); } else { /**Execute default query listener with help of invokeEL method*/ invokeEL("#{bindings.DepartmentsViewCriteriaQuery.processQuery}", new Class[] { QueryEvent.class }, new Object[] { queryEvent }); } }
/**Custom Query Listener-Using QueryDescriptor * @param queryEvent */ public void customqueryProcess(QueryEvent queryEvent) { String deptName = null; Integer locId = null; Integer mgrId = null; /**Reference-Frank Nimphius Example- ADF Code Corner * http://www.oracle.com/technetwork/developer-tools/adf/learnmore/85-querycomponent-fieldvalidation-427197.pdf * */ QueryDescriptor qd = queryEvent.getDescriptor(); ConjunctionCriterion conCrit = qd.getConjunctionCriterion(); //access the list of search fields List<Criterion> criterionList = conCrit.getCriterionList(); //iterate over the attributes to find FromDate and ToDate for (Criterion criterion : criterionList) { AttributeDescriptor attrDescriptor = ((AttributeCriterion)criterion).getAttribute(); if (attrDescriptor.getName().equalsIgnoreCase("DepartmentName")) { deptName = (String)((AttributeCriterion)criterion).getValues().get(0); } else { if (attrDescriptor.getName().equalsIgnoreCase("LocationId")) { locId = (Integer)((AttributeCriterion)criterion).getValues().get(0); } } if (attrDescriptor.getName().equalsIgnoreCase("ManagerId")) { mgrId = (Integer)((AttributeCriterion)criterion).getValues().get(0); } } if ((locId != null && locId < 0) || (mgrId != null && mgrId < 0)) { FacesMessage msg = new FacesMessage("Id Value can not be negative"); msg.setSeverity(FacesMessage.SEVERITY_ERROR); FacesContext.getCurrentInstance().addMessage(null, msg); } else { /**Process default query listener*/ invokeEL("#{bindings.DepartmentsViewCriteriaQuery.processQuery}", new Class[] { QueryEvent.class }, new Object[] { queryEvent }); } }