Previously I have posted about populating selectOneChoice programmatically using POJO
and this post is about getting selected value of POJO base selectOneChoice (both display value and base value)
Blog about Oracle ADF, JDeveloper, PL/SQL, Java, JavaScript, jQuery and Other Web Technologies
/**Value Change Listener of DeptIdTrans (to get selected and display value) * @param vce */ public void deptIdVCE(ValueChangeEvent vce) { System.out.println("New Value is-" + vce.getNewValue()); if (vce.getNewValue() != null) { this.setvalueToExpression("#{row.bindings.DeptIdTrans.inputValue}", vce.getNewValue()); //Updating Model Values Integer selectedCode = Integer.parseInt(this.getValueFrmExpression("#{row.bindings.DeptIdTrans.attributeValue}").toString()); System.out.println("******** Selected Value in List***** " + selectedCode); System.out.println("*******Display Value in List ****" + getValueFrmExpression("#{row.bindings.DeptIdTrans.selectedValue.attributeValues[1]}")); } }
/**Method to set value in Expression (EL) * @param el * @param val */ public void setvalueToExpression(String el, Object val) { FacesContext facesContext = FacesContext.getCurrentInstance(); ELContext elContext = facesContext.getELContext(); ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory(); ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class); exp.setValue(elContext, val); } /**Method to get value from Expression (EL) * @param data * @return */ public String getValueFrmExpression(String data) { FacesContext fc = FacesContext.getCurrentInstance(); Application app = fc.getApplication(); ExpressionFactory elFactory = app.getExpressionFactory(); ELContext elContext = fc.getELContext(); ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class); String Message = null; Object obj = valueExp.getValue(elContext); if (obj != null) { Message = obj.toString(); } return Message; }