0

I am developing pagination logic using JSF1.2 and in the process I have 4 links for first, previous, next and last pages corresponding to the results. I enter the search criteria in the Search page and click submit to get some records. I have a view link corresponding to each of the records to see the complete details. So I have two Managed beans one for Search/pagination functionality and other for View complete record details.

Whats the problem then?

When I search for the records the pagination works completely fine. However when I view the details of a record and come back to search page, I find that every time I click the next button the next() method is getting called twice.

Is there any solution for this?

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);
        }
    }
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Dhana
  • 505
  • 1
  • 8
  • 27
  • Can you show a bit more code from your xhtml? Especially if you have a condition around your _h:commandLink_, and in which scope your _searchRoutesForView_ – Manuel Jan 05 '13 at 17:52

1 Answers1

0

Please have a look at the lifecyle of JSF

Below approach may not be the best one..

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

This will not work if bean is in Request scope.

Vikas V
  • 3,176
  • 2
  • 37
  • 60