0

JSF1.2 を使用してページネーション ロジックを開発しています。その過程で、結果に対応する最初、前、次、および最後のページの 4 つのリンクがあります。[検索] ページに検索基準を入力し、[送信] をクリックしていくつかのレコードを取得します。完全な詳細を表示するために、各レコードに対応するビュー リンクがあります。そのため、検索/ページネーション機能用と完全なレコード詳細の表示用の 2 つのマネージド Bean があります。

じゃあ何が問題なの?

レコードを検索すると、ページネーションは完全に正常に機能します。しかし、レコードの詳細を表示して検索ページに戻ると、次のボタンをクリックするたびに next() メソッドが 2 回呼び出されていることがわかります。

これに対する解決策はありますか?

The code is as follows:-

Inside search:-
 <h:commandLink value="#{msg['heading.nextLink']}"
                                            binding="#{searchRoutesForView.nextLink}" 
                                            actionListener="#{searchRoutesForView.next}">
                                        </h:commandLink>

Inside SearchManagedbean:-

public void next(ActionEvent actionEvent) {

        if ((pointer + noOfRecordsToBeDisplayed) >= readConfig.length) {
            readRoutingResponse.setReadConfig(Arrays.copyOfRange(readConfig,
                    pointer, readConfig.length));
            pointer = readConfig.length;
            System.out.println("pointer inside next =" + pointer);
            setOrDisableLinks(false, false, true, true);
        } else {
            readRoutingResponse.setReadConfig(Arrays.copyOfRange(readConfig,
                    pointer, pointer + noOfRecordsToBeDisplayed));
            pointer += noOfRecordsToBeDisplayed;
            System.out.println("pointer inside next -- else =" + pointer);
            setOrDisableLinks(false, false, false, false);
        }
    }
4

1 に答える 1

0

JSFのライフサイクルを見てください

以下のアプローチは最善の方法ではないかもしれません..

public void next(ActionEvent actionEvent)
{
   if((pointer + noOfRecordsToBeDisplayed) >= readConfig.length) && (isVisitedOnce == false))
     {
        visitedOnce = true //set one boolean indicating this method is already visited 
      }
}

Bean が Request スコープにある場合、これは機能しません。

于 2012-12-31T12:16:30.047 に答える