0
votes

I have a page where when user will login then he will be dispalyed a list of his 15 recent records created.The jsf page is having two forms one form is having few fields for search criteria and command button.and another form is having a datatable which will fetch the records and display it.In data table last column is having some links displayed based on status.

To display the records in h:datatable tag i am using a backing bean RecordSearchBean property records which will fetch the records if that beans's search proerties are null. RecordSearchBean is having proerties:

fromDate(used for search criertia) toDate(used for search criertia) records(used to display the records) fetchRecords()(method to get the recent 15 records for user) searchRecords(ActionEvent e)(invoked by search button on jsf page)

public list getRecentRecord(){

if(fromDate==null && toDate == null){ this.records=fetchRecords(); } return this.records; }

public List fetchRecords(){ //code to get the list of records }

public void searchRecords(ActionEvent e){ //code to get the records based on search criteria List searchedRecords=getREcords(this); this.records=searchedRecords; }

This RecordSearchBean is in request scope.

What i am doing in jsf is when user will login then he will get the records populated by records property and display in datatable.

when user will click on search button on jsf page ,the records property will be populated by searchRecords actionlistener. Till then everything is working proerly but when i m clicking on any link provided by the datatable in last column of record then again i am getting the list of records which were display when user has logged in.

There is one home page tab in menu when user will click on this tab he will get the list of 15 records which was displayed to user when he logs in.

I think this propeblem is something related to jsf managed bean scope.If i will change the scope of bean then every link in last column of databale is working properly.

In that case if the user will click on home page then he will not get the list of records which he had got when he logged in.

Please help me.

1

1 Answers

0
votes

I think the problem could (as you have already stated) be related to the RequestScoped. If you click on a link, the Bean will be newly instantiated and all properties will be reset.

Try to use ViewScoped instead and reset fromDate and toDate to null if the HomePage tab is clicked. In ViewScope the Bean will not be re-instantiated if you reload the same page by returning null from a method.