ADF中選擇表行後改變當前行的編輯狀態,adf當前
現在要實現在table中,選中某一行,該行的上傳按鈕可用,不選中的行為不可用,如下實現效果:
具體實現方式如下:
1、對應的table代碼,用<selectionListener>屬性關聯實作類別
<af:table value="#{bindings.PtsTestVVO1.collectionModel}"
var="row" width="100%"
rows="#{bindings.PtsTestVVO1.rangeSize}"
first="#{bindings.PtsTestVVO1.rangeStart}"
emptyText="#{bindings.PtsTestVVO1.viewable ? 'No rows yet.' : 'Access Denied.'}"
selectionListener="#{testBean.selectionChanged}"
banding="none"
binding="#{testBean.testTable}">
2、對應“上傳”按鈕的代碼,注意這裡disabled的寫法
<af:commandButton text="#{res['UPLOAD']}"
useWindow="true"
windowHeight="600" windowWidth="450"
immediate="true" disabled="#{row.Flag=='0'?true:false}"
action="#{testBean.uploadFile}">
3、在對應實作類別中,每次選中當前行,改變flag的值
public void selectionChanged(SelectionEvent selectionEvent) {
UIComponent cmp = selectionEvent.getComponent();
//取當前TABLEID
DCBindingContainer tableBindings =
(DCBindingContainer)getDCBindingContainer();
DCIteratorBinding iterBinding= tableBindings.findIteratorBinding("PtsTestVVO1");
String strID = cmp.getId();
CoreTable tableReceiptOrderAssign = this.getTableOjb(strID);
//遍曆VO set Falg\
ViewObject VO = this.getPtsAM().findViewObject("PtsTestVVO1");
int rowCount;
int rowCount0 = VO.getRowCount();
int rowCount1 = VO.getRangeSize();
if (rowCount0 >= rowCount1) {
rowCount = rowCount1;
} else {
rowCount = rowCount0;
}
for (int i = 0; i < rowCount; i++) {
VO.getRowAtRangeIndex(i).setAttribute("Flag", "0");
}
Set rowSet = tableReceiptOrderAssign.getSelectionState().getKeySet();
if (rowSet.size() == 0) {
return;
}
Iterator rowSetIter = rowSet.iterator();
while (rowSetIter.hasNext()) {
Key key = (Key)rowSetIter.next();
iterBinding.setCurrentRowWithKey(key.toStringFormat(true));
RowImpl curentRow = (RowImpl)iterBinding.getCurrentRow(); //得到當前行
curentRow.setAttribute("Flag", "1"); //設定標緻位
}
AdfFacesContext.getCurrentInstance().addPartialTarget(tableReceiptOrderAssign);
}