ADF af:表恢复表状态

问题描述 投票:3回答:2

我对ADF Faces表和动态区域有疑问。

前提条件:Oracle JDeveloper 11.1.1.6.0

我正在使用ADF Faces和ADF绑定层在af:table中显示Java POJO的列表。ADF表显示在受限任务流内的视图上。此任务流在另一个视图的动态区域中使用。导航包含两个链接,这些链接用于通过bean属性选择限制任务流以显示在动态区域中。动态区域通过任务流绑定接收“输入参数图”。该映射包含要在表中显示的POJO和一个状态Bean,该状态Bean应保存表状态以及视图中可能存在的其他组件的状态(请参见下面的实现)。

问题/要求:

1。预选:

根据第一次加载表时根据POJO中包含的数据预先选择表中的一行。

2。继续选择任务流开关:

在切换到另一个有界任务流B并返回到A(表所在的位置)之后,还应该选择表中的选定行(有界任务流A)。

3。没有MDS

不使用保存点/ MDS功能。

4。一致的表模型和绑定层

在任务流之间切换以及在表中选择元素之后,应该可以询问表组件和所选行的绑定。切换任务流和选择表中的元素之后,绑定中的表行和所选行应保持一致。

已经尝试:

预选一行,并在不使用MDS /保存点的情况下继续选择任务流切换。

我已将某些表属性绑定到“状态” Bean。该bean的实现见下面的附件。

1。表格的属性:

所选行键:selectedRowKeys =“#{pageFlowScope.stateBean.tableStateBean.rowKeySet}”

Backing-Bean属性以绑定RichTable:binding =“#{pageFlowScope.stateBean.tableStateBean.richTable}”

默认选择监听器selectionListener =“#{bindings.postanschriften.collectionModel.makeCurrent}”]

我们在这里尝试过的事情:在表的初始加载和更改行Bean方法时,将调用getRowKeySet(..)方法。在此方法中,要在初始表加载时计算要选择的行(this.rowKeySet == null)。因为表属性selectedRowKeys绑定到pageFlowScope.stateBean.tableStateBean.rowKeySet,所以如果在表中选择了另一行,则Bean中的属性将更新。如果我们将任务流程从A更改为B,反之亦然,则将调用支持bean属性richTable的吸气剂。在getter方法中,恢复了选择状态。

2。执行“状态” bean:

public class TableStateBean {
    private RichTable richTable;
    private RowKeySet rowKeySet;
    private String bindingIteratorName;
    private RowMatcher matcher;

public RowKeySet getRowKeySet() {
    if (this.rowKeySet == null) {
        preselectRow();
    }
    return rowKeySet;
}

public RichTable getRichTable() {
    if (richTable != null && rowKeySet != null) { 
        RowKeySet currentTableSelection = getCurrentTableSelection();
        RowKeySet tableSelectionToRestore = getTableSelectionToRestore();
        executeSelection(tableSelectionToRestore, currentTableSelection);
    }
    return richTable;
}

public void setRichTable(RichTable pRichTable) {
    richTable = pRichTable;
}

public void doTableSelection(){
    preselectRow();
}


private RowKeySet getCurrentTableSelection() {
    Row currentRow = (Row) JSFUtils.resolveExpression("#{bindings." + this.bindingIteratorName + ".currentRow}");
    Key currKey = currentRow.getKey();
    ArrayList<Key> lst = new ArrayList<Key>(1);
    lst.add(currKey);
    RowKeySet keySet = new RowKeySetImpl();
    keySet.add(lst);
    return keySet;
}

private RowKeySet getTableSelectionToRestore() {
    RowKeySet tableSelectionToRestoreRow = null;
    RowSetIterator rowSetIterator = extractRowSetIterator();
    int tableRowIndexOfCurrentSelectedKey = getSingleRowKeyIndexValue(this.rowKeySet);

    if (tableRowIndexOfCurrentSelectedKey != -1) {
        Row currentRow = rowSetIterator.first();
        for (int i = 0; rowSetIterator.hasNext() && i < tableRowIndexOfCurrentSelectedKey; i++) {
            currentRow = rowSetIterator.next();
        }
        if (currentRow != null) {
            Key newSelectionKey = currentRow.getKey();

            ArrayList<Key> keyList = new ArrayList<Key>(1);
            keyList.add(newSelectionKey);

            tableSelectionToRestoreRow = new RowKeySetImpl();
            tableSelectionToRestoreRow.add(keyList);
        }
    }

    return tableSelectionToRestoreRow;
}

private int getSingleRowKeyIndexValue(RowKeySet rowKeySet) {
    int tableRowIndexOfCurrentSelectedKey = -1;

    if (rowKeySet != null) {
        Object[] rowKeySetArray = rowKeySet.toArray();
        List<Key> selectedRowKeys = (rowKeySetArray.length > 0) ? (List<Key>) rowKeySetArray[0] : new ArrayList<Key>();
        if (selectedRowKeys.size() > 0) {
            Key currentSelectedKey = selectedRowKeys.get(0);
            Object[] attributeValues = currentSelectedKey.getAttributeValues();
            assert (attributeValues.length > 0);
            tableRowIndexOfCurrentSelectedKey = (Integer) attributeValues[0];
        }
    }
    return tableRowIndexOfCurrentSelectedKey;
}

private void executeSelection(RowKeySet newCurrentRow, RowKeySet oldCurrentRow) {
    SelectionEvent selectionEvent = new SelectionEvent(oldCurrentRow, newCurrentRow, richTable);
    selectionEvent.queue();
    AdfFacesContext.getCurrentInstance().addPartialTarget(richTable);
}

protected void preselectRow() {
    RowSetIterator rowSetIterator = extractRowSetIterator();

    RowKeySet oldSelection = getCurrentTableSelection();        
    Row currentRow = rowSetIterator.first();
    while (rowSetIterator.hasNext() 
           && (!matcher.match(currentRow))) // Matcher selects which row should be displayed according to the Object bound behind the binding-layer.
    {
        currentRow = rowSetIterator.next();
    }
    if (currentRow != null) {

        Key key = currentRow.getKey();
        RowKeySet newSelection = createRowKeySet(key);            
        setActiveRowKey(key);
        executeSelection(newSelection, oldSelection);
        setRowKeySet(newSelection);
    }
}

private void setActiveRowKey(Key pKey) {
    ArrayList<Key> lst = new ArrayList<Key>(1);
    lst.add(pKey);
    this.richTable.setActiveRowKey(lst);
}

private RowKeySet createRowKeySet(Key pKey) {
    ArrayList<Key> lst = new ArrayList<Key>(1);
    lst.add(pKey);
    RowKeySetImpl rowKeySetToCreate = new RowKeySetImpl();
    rowKeySetToCreate.add(lst);
    return rowKeySetToCreate;
}

private RowSetIterator extractRowSetIterator() {
    DCIteratorBinding iteratorBinding = ADFUtils.findIterator(this.bindingIteratorName);
    RowSetIterator rowSetIterator = iteratorBinding.getRowSetIterator();
    return rowSetIterator;
    }
}

似乎在某些情况下,绑定层与RichTable组件上选择的元素不同步。所以我想上面提到的解决方案不是很健壮。

还有另一种方法可以以健壮的方式存档上述功能吗?我认为根据绑定的POJO中的某些值预先选择表中的一行并不奇怪。并且在有边界的任务流(动态区域)之间切换之后,还应该保留表的选定行,不是吗?

感谢您的帮助

问候,

最大

jsf oracle-adf
2个回答
0
投票

设置“选定”行非常容易。有几种解决方案。这只是其中之一:为表绑定到支持bean。在getter中,添加以下代码:

DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dcItteratorBindings =
bindings.findIteratorBinding("yourViewObjectIterator");
RowSetIterator it = dcItteratorBindings.getRowSetIterator();
Rows[] rows = voTableData.getAllRowsInRange();
Row needsSelection = null;
for(Row r: rows)
{
   //just search for the row you want to set selected
  if(r.getAttribute("SomeAttribute").eqauls(..))
     needsSelection = r;
}

if(needsSelection != null)
it.setCurrentRow(needsSelection);

0
投票

您可能希望查看您的应用程序设计。使用单个任务流在两个视图活动(页面片段)之间进行导航可能是一种更简单的解决方案,而不是使用动态区域并在两个任务流之间进行切换。另外,您已经编写了很多代码,仅用于保留行选择。您只需要为所选行存储唯一列的数据,并使用上面的DCBinding Iterator中提供的逻辑将行选择设置为该行。

© www.soinside.com 2019 - 2024. All rights reserved.