上篇 ADF Table : Row selection using checkboxes 覺得那樣作有點麻煩, 經過思考及整理後, 覺得下列作法較佳:
前置作業:
1. 使用 Table: USERS 來作示範
CREATE TABLE "USERS"( "USERNAME" VARCHAR2(15 BYTE) NOT NULL PRIMARY KEY ENABLE , "NAME" VARCHAR2(255 BYTE) NOT NULL ENABLE, "PASSWORD" VARCHAR2(15 BYTE) NOT NULL ENABLE ) |
Step 01:
建立的 EO (Entity Objects): UsersEO 自行加入一個暫時記錄資料(transient attribute)的欄位 Selected , Type: Boolean, 因不需回寫 Table, 所以將屬性 Persistent 拿掉
Step 02: 建立 VO: UsersVO,並加入三個 function 於 UsersVOImpl 中: selectAll(), deSelectAll(), deleteSelectedRows()
import com.wei.model.vo.common.UsersVO;
import oracle.jbo.Row; import oracle.jbo.RowSet; import oracle.jbo.RowSetIterator; import oracle.jbo.server.ViewObjectImpl; // --------------------------------------------------------------------- // --- File generated by Oracle ADF Business Components Design Time. // --- Fri Jun 13 15:21:46 CST 2014 // --- Custom code may be added to this class. // --- Warning: Do not modify method signatures of generated methods. // --------------------------------------------------------------------- public class UsersVOImpl extends ViewObjectImpl implements UsersVO { /** * This is the default constructor (do not remove). */ public UsersVOImpl() { }
public void selectAll(){ RowSetIterator row = this.getRowSetIterator(); row.reset(); if (row.first() != null) { Row r = row.first(); r.setAttribute("Selected", true); } while(row.hasNext()){ Row r = row.next(); r.setAttribute("Selected", true); } } public void deSelectAll(){ RowSetIterator row = this.getRowSetIterator(); row.reset(); if (row.first() != null) { Row r = row.first(); r.setAttribute("Selected", false); } while(row.hasNext()){ Row r = row.next(); r.setAttribute("Selected", false); } } public void deleteSelectedRows() { Row[] selectedRowsToDelete = this.getFilteredRows("Selected",true); if (selectedRowsToDelete.length>0){ for ( Row row: selectedRowsToDelete) { row.remove(); } } this.executeQuery(); this.getDBTransaction().commit(); //直接刪除資料 } }
|
Step 03: 將自建的 function 註冊, 以便轉換可使用的 method
Step 04: 將註冊好的 method 拖拉至 tableCheckBoxSelect.jspx 中使用.
執行的結果如下, 這樣是不是很簡便呢?
參考文件:
http://docs.oracle.com/cd/B14099_19/web.1012/b14022/overview-summary.html
https://java.net/projects/smuenchadf/pages/ADFSamples
http://jdevadf.oracle.com/
留言列表