ADF中遍历VO行记录不止一种方法,但项目开发中仍有区别,如下给出两种方法。
1.通过VO直接取行:
TargetRunVarForUpdatedImpl vo = (TargetRunVarForUpdatedImpl)getViewObject(“TargetRunVarForUpdatedIterator”); int i = 0; Row row = null; vo.reset(); while (vo.hasNext()) { if (i == 0) row = vo.first(); else row = vo.next(); String flag=(String)row.getAttribute(“selectedFlag”); if(flag==null||flag.equals(“”)){} else if(flag.equals(“Y”)) { row.setAttribute(“Flag”, (Number)(2)); } i++; } this.getTransaction().commit();
2.通过RowSet取行:
TargetRunVarForUpdatedImpl vo = (TargetRunVarForUpdatedImpl)getViewObject(“TargetRunVarForUpdatedIterator”); RowSetIterator it = vo.createRowSetIterator(null); it.reset(); while(it.hasNext()){ Row row=it.next(); String flag=(String)row.getAttribute(“selectedFlag”); if(flag==null||flag.equals(“”)){} else if(flag.equals(“Y”)) { row.setAttribute(“Flag”, (Number)(2)); } } this.getTransaction().commit();
测试表明两种方法一般情况下均可遍历行处理相关字段,但是在VO作为table呈现在页面时,若当前只有一条记录,方法1不能迭代到。因此开发过程中通过遍历VO建议选用方法2。
时间: 2024-12-28 10:38:00