2012-11-20 3 views
3

ADF Faces 테이블 및 동적 영역과 관련하여 문제가 있습니다.ADF af : 테이블 복원 테이블 상태

전제 조건 : 테이블 : 내가 아프 자바 POJO의 목록을 표시 ADF 얼굴과 ADF 바인딩 레이어를 사용하고 11.1.1.6.0


오라클 JDeveloper를. ADF 테이블은 제한된 태스크 플로우 내부의 뷰에 표시됩니다.
이 태스크 플로우는 다른보기의 동적 region에서 사용됩니다.
탐색에는 동적 영역에 표시 할 태스크 흐름을 제한하는 bean-property를 통해 선택하는 데 사용되는 두 개의 링크가 있습니다.
동적 영역은 태스크 흐름 바인딩을 통해 "입력 매개 변수 맵"을 수신합니다.
이 맵은 테이블에 표시 할 POJO와 뷰에있는 가능한 다른 구성 요소의 테이블 상태 및 상태를 보유해야하는 state-Bean을 포함합니다 (아래 구현 참조).

문제/요구 사항

1. 사전 선택 :

사전 선택 테이블의 첫 번째로드에서 POJO에 포함 된 데이터에 따라 상기 테이블 내의 단일 행. taskflow 스위치 위에

2. 보관할 선택 : 테이블 (경계 taskflow의 A)에서 선택된 행은 테이블의 위치 (A 다시 다른 경계 taskflow를 B로 전환하고 후 선택해야

).

3. 없음 MDS

세이브 포인트/MDS 기능 없음 사용.

4. 일관된 나타난 모델과 결합 층

가 작업 흐름을 전환 한 후, 테이블의 요소를 선택한 후에 나타난 성분 및 선택된 로우에 대한 바인딩을 요청할 수 있어야한다.
바인딩에서 테이블 행과 선택된 행은 작업 흐름을 전환 한 후 테이블에서 요소를 선택한 후에 일관성을 유지해야합니다. 행의

사전 선택 및 MDS/세이브 포인트를 사용하지 않고 작업 흐름 스위치를 통해 선택을 계속 :

은 이미 시도했다.

"상태"bean에 일부 테이블 속성을 바인딩했습니다. 빈의 구현은 아래에 첨부되어 있습니다. 테이블의

1. 속성 :

선정 행 키 :
selectedRowKeys = "# {pageFlowScope.stateBean.tableStateBean.rowKeySet} "

백업 - 콩 속성 RichTable 바인딩 :
바인딩 ="# {pageFlowScope.stateBean.tableStateBean.richTable} "

기본 선택 리스너
selectionListener ="# {바인딩 테이블의 초기로드에

를하고 소유주 변경 : .postanschriften.collectionModel.makeCurrent} "

우리는 여기에 시도 무엇 w bean 메소드 getRowKeySet (..)이 호출됩니다.
이 메소드에서 선택할 행은 초기 테이블로드 (this.rowKeySet == null)에서 계산됩니다. selectedRowKeys 테이블 속성이 pageFlowScope.stateBean.tableStateBean.rowKeySet에 바인딩되어 있기 때문에 테이블에서 다른 행을 선택하면 Bean의 속성이 업데이트됩니다. 태스크 플로우를 A에서 B로 또는 그 반대로 변경하면 backing bean 특성 인 richTable의 getter가 호출됩니다. getter 메서드에서 선택 상태가 복원됩니다. 은 "상태"콩

2. 구현 :

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의 일부 값에 따라 테이블의 행을 미리 선택하는 것이 이상하다고 생각하지 않습니다. 또한 바운드 된 작업 흐름 (동적 영역) 사이를 전환 한 후에 테이블의 선택된 행을 유지하는 것이 가능해야합니까?

는 당신의 도움을 기대

감사합니다,

최대

답변

0
는 '선택'행을 설정

오히려 쉽게 감사합니다. 거기에는 몇 가지 해결책이 있습니다. 이것은 다음 중 하나 일뿐입니다. 빈을지지하는 테이블에 대한 바인딩을 만듭니다. 당신은 당신의 애플리케이션 설계를 검토 할 수 있습니다

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

안녕하세요. 동적 영역에 바인딩 된 작업 흐름을 변경하는 동안 테이블 상태를 유지하려고합니다. 예 : 작업 흐름 A를로드하고 행을 미리 선택합니다. 5. 행 7을 선택합니다. 작업 흐름 B로 변경합니다. 작업 흐름으로 돌아갑니다. 이제 행 7이 선택되어야합니다. – Max

+0

작업 흐름을 변경할 때마다 선택된 행의 식별자를 전달하거나 선택한 행/식별자를 보유하는 특정 범위 (사용 사례에 따라)로 관리 빈을 정의 할 수 있습니다. – User404

+0

우리는 이미 RowKeySet을 식별자로 사용하려고했습니다. 그러나 문제는 테이블을 정렬하는 동안 포함 된 키가 변경된다는 것입니다. – Max

0

: 게터에서 는 다음과 같은 코드를 추가합니다. 단일 작업 흐름을 사용하여 두 뷰 활동 (페이지 조각) 사이를 탐색하는 것은 동적 영역을 사용하고 두 작업 흐름 사이를 전환하는 대신 더 간단한 해결책 일 수 있습니다. 또한 행 선택을 유지하기위한 많은 코드를 작성했습니다. 선택한 행의 고유 한 열에 대한 데이터를 저장하고 DCBinding Iterator를 사용하여 위의 게시물에 제공된 논리를 사용하여 행 선택을 해당 행에 설정하면됩니다.

관련 문제