refer below lik
http://www.rsantrod.com/2016/08/adf-update-model-in-value-change.html
-- this is the example
public void popNewProducts(ValueChangeEvent vce) {
//
vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
if (this.getSor2().getValue().equals("N")) {
PreparedStatement pstmt = null;
ResultSet rs = null;
//String catCode = (String)this.getCatCodeId().getValue();
String catCode = (String)vce.getNewValue();
HashMap<String, String> hm = new HashMap<String, String>();
hm = (HashMap<String, String>)resolveExpression("#{pageFlowScope.ParamsBean.parm_obj}");
System.out.println("hm==" + hm);
String vcomp_mode = hm.get("COMP_CODE");
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc = bindingContext.findDataControl("AppModuleAMDataControl");
AppModuleAMImpl appM = (AppModuleAMImpl)dc.getDataProvider();
String query = "select distinct a.prod_code\n" +
"from pi_product_mst a,pi_prod_price_defn b\n" +
"where a.prod_code = b.prod_code\n" +
"and a.prod_id = b.prod_id\n" +
"and a.comp_code = ?\n" +
"and a.cat_code = ?\n" +
"and b.prod_price is not null\n" +
"and nvl(a.active_yn,'Y') = 'Y'";
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dcItteratorBindings1 = bindings.findIteratorBinding("PiProdPriceDefnVO2Iterator");
ViewObject voDtl = dcItteratorBindings1.getViewObject();
//System.out.println("before create");
voDtl.createRow();
System.out.println("after create");
pstmt = appM.getDBTransaction().createPreparedStatement(query, 1);
try {
pstmt.setString(1, vcomp_mode);
pstmt.setString(2, catCode);
rs = pstmt.executeQuery();
int x = 1;
if (voDtl.getRowCount() > 0) {
System.out.println("greter than zero");
while (voDtl.hasNext()) {
System.out.println("Inside while");
voDtl.removeCurrentRow();
System.out.println(x);
x++;
}
voDtl.first();
voDtl.removeCurrentRow();
}
while (rs.next()) {
System.out.println("voDtl " + voDtl);
//Row r = appM.getPiProdPriceDefnVO2().createRow();
Row r = voDtl.createRow();
String vprodCode = rs.getString(1);
System.out.println(r + " r " + vprodCode);
r.setAttribute("ProdCode", vprodCode);
}
AdfFacesContext.getCurrentInstance().addPartialTarget(t1);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
http://www.rsantrod.com/2016/08/adf-update-model-in-value-change.html
-- this is the example
public void popNewProducts(ValueChangeEvent vce) {
//
vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
if (this.getSor2().getValue().equals("N")) {
PreparedStatement pstmt = null;
ResultSet rs = null;
//String catCode = (String)this.getCatCodeId().getValue();
String catCode = (String)vce.getNewValue();
HashMap<String, String> hm = new HashMap<String, String>();
hm = (HashMap<String, String>)resolveExpression("#{pageFlowScope.ParamsBean.parm_obj}");
System.out.println("hm==" + hm);
String vcomp_mode = hm.get("COMP_CODE");
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc = bindingContext.findDataControl("AppModuleAMDataControl");
AppModuleAMImpl appM = (AppModuleAMImpl)dc.getDataProvider();
String query = "select distinct a.prod_code\n" +
"from pi_product_mst a,pi_prod_price_defn b\n" +
"where a.prod_code = b.prod_code\n" +
"and a.prod_id = b.prod_id\n" +
"and a.comp_code = ?\n" +
"and a.cat_code = ?\n" +
"and b.prod_price is not null\n" +
"and nvl(a.active_yn,'Y') = 'Y'";
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dcItteratorBindings1 = bindings.findIteratorBinding("PiProdPriceDefnVO2Iterator");
ViewObject voDtl = dcItteratorBindings1.getViewObject();
//System.out.println("before create");
voDtl.createRow();
System.out.println("after create");
pstmt = appM.getDBTransaction().createPreparedStatement(query, 1);
try {
pstmt.setString(1, vcomp_mode);
pstmt.setString(2, catCode);
rs = pstmt.executeQuery();
int x = 1;
if (voDtl.getRowCount() > 0) {
System.out.println("greter than zero");
while (voDtl.hasNext()) {
System.out.println("Inside while");
voDtl.removeCurrentRow();
System.out.println(x);
x++;
}
voDtl.first();
voDtl.removeCurrentRow();
}
while (rs.next()) {
System.out.println("voDtl " + voDtl);
//Row r = appM.getPiProdPriceDefnVO2().createRow();
Row r = voDtl.createRow();
String vprodCode = rs.getString(1);
System.out.println(r + " r " + vprodCode);
r.setAttribute("ProdCode", vprodCode);
}
AdfFacesContext.getCurrentInstance().addPartialTarget(t1);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment