现在要实现在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);
}