表中的ADF复选框,所选行缺少计时

  • 本文关键字:ADF 复选框 java oracle-adf
  • 更新时间 :
  • 英文 :


我有一个表,其中第一列应该是一个复选框,这样你就可以选择一堆行,现在只需将其添加到存储在pageflowscope中的列表中。问题是,单击复选框有时会使选定的行滞后,并添加错误的行。例如,我单击第一行中的复选框,然后在它处理时,我取消选中它,然后单击另一个复选框,它仍然会添加第一行,因为它认为所选的行仍然是第一行。

表:

<af:table value="#{bindings.documents.collectionModel}" var="row" rows="#{bindings.documents.rangeSize}"
emptyText="#{bindings.documents.viewable ? 'No data to display.' : 'Access Denied.'}"
rowBandingInterval="0" selectedRowKeys="#{bindings.documents.collectionModel.selectedRow}"
selectionListener="#{bindings.documents.collectionModel.makeCurrent}" rowSelection="single"
fetchSize="#{bindings.documents.rangeSize}" filterModel="#{bindings.documentsQuery.queryDescriptor}"
filterVisible="true" queryListener="#{bindings.documentsQuery.processQuery}" varStatus="vs" id="t1"
autoHeightRows="0" styleClass="AFStretchWidth" scrollPolicy="page">
<af:column id="c41" align="center" width="50">
<?audit suppress oracle.adf.faces.tablecolneedsheaders?>
<af:selectBooleanCheckbox id="sbc1" valueChangeListener="#{CopyQueueBean.toggleCheckbox}"
autoSubmit="true">
<?audit suppress oracle.adf.faces.compnotlabelled?>
</af:selectBooleanCheckbox>
</af:column>
<af:column sortProperty="#{bindings.documents.hints.id.name}" filterable="true" sortable="true"
headerText="#{labels.ID}" id="c1" align="center">
<af:outputText value="#{row.id}" shortDesc="#{bindings.documents.hints.id.tooltip}" id="ot1"/>
</af:column>
<af:column sortProperty="#{bindings.documents.hints.fileName.name}" filterable="true" sortable="true"
headerText="#{labels.TITLE}" id="c4" align="center" width="400">
<af:panelGroupLayout id="pgl2" styleClass="AFStretchWidth" inlineStyle="float:left; text-align:left;">
<af:spacer width="20px" id="leftIconSpacer" />
<af:image source="#{row.icon}" id="i6"
inlineStyle="width:40.0px;"/>
<af:spacer width="40px" id="iconSpacer" />
<af:outputText value="#{row.fileName}" id="fot2"/>
</af:panelGroupLayout>
</af:column>

My Bean方法:

public void toggleCheckbox(ValueChangeEvent valueChangeEvent) {
// Add event code here...
Boolean checked = (Boolean) valueChangeEvent.getNewValue();
//get list
ADFContext adfCtx = ADFContext.getCurrent();
Map params = adfCtx.getPageFlowScope();
List<Row> list = (List<Row>) params.get("docQueue");
if (list == null) {
list = new ArrayList<CopyQueuePojo>();
}
DCBindingContainer bindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding documents = bindings.findIteratorBinding("documentsIterator");
int index = documents.getCurrentRowIndexInRange();
Row[] rows = documents.getAllRowsInRange();
Row line = rows[index];
if (checked) {
//add to queue
if (index >=  0) {                
//check to make sure there are no duplicates
boolean exists = false;
for(int i=0; i<list.size(); i++) {
if(list.get(i).getId() == ((String) line.getAttribute("id"))) {
exists = true; 
break;
}
}
if (!exists) {                    
list.add(line);
}
}
} else {
//remove from queue
for(int i=0; i<list.size(); i++) {
if(list.get(i).getId() == ((String) line.getAttribute("id"))) {
list.remove(i);
}
}
}
params.put("docQueue", list);
}

开发人员:12.2.1.2.0

我应该使用不同的方式来设置所选行吗?或者我不应该使用valuechangelistener?还是别的东西?

将selectBooleanCheckbox添加到基于ViewObject的表的最佳方法是将布尔瞬态值添加到您的ViewObject。这样做可以为每一行保存不同的布尔值,并以与其他列值相同的方式轻松访问它。

为此:

1( 将isSelected布尔瞬态属性添加到ViewObject:

<ViewAttribute
Name="isSelected"
IsSelected="false"
IsPersistent="false"
PrecisionRule="true"
Type="java.lang.Boolean"
ColumnType="NUMBER"
AliasName="VIEW_ATTR"
SQLType="BIT"
Passivate="true">
<DesignTime>
<Attr Name="_diagramName" Value=" "/>
</DesignTime>
<Properties>
<SchemaBasedProperties>
<CONTROLTYPE
Value="check_box"/>
<DISPLAYWIDTH
Value="10"/>
<DISPLAYHEIGHT
Value="10"/>
</SchemaBasedProperties>
</Properties>

2( 将ViewObject作为表格拖放到视图中,您应该添加以下列:

<af:column sortable="false" id="c1" width="20">
<af:selectBooleanCheckbox value="#{row.bindings.isSelected.inputValue}" label="#{row.bindings.isSelected.label}" id="sbc1"/>
</af:column>

3( 在你的Bean操作中,很容易得到你的布尔值:

Boolean val = (Boolean )JSFUtils.resolveExpression("#{row.bindings.isSelected.inputValue}");

最新更新