I'm wondering if there is a common pattern for the following scenario.
Let's say I have one JSF page backed with one request scoped bean. I want to fech all data rows from a database table when a user enters this page. The same JSF page contains a form to provide query criteria. When the user provides query criteria and submits the form, I want to display the result on the same page, too.
The suitable place to fetch all rows at page entry is the @PostConstruct method. This is a nice place to do that since additional (injected) request parameters are already available here and can be used in the query. However, parameters submited from the form are not available yet. They can be accessed in the action method.
If the user queries the database table using the form criteria the database will be queried twice in this case. The request scoped bean will be recreated and @PostConstruct method fetching all rows will be called prior to the form action method fetching what the user wants.
Of course I could redirect the form result to another JSF page backed by a different bean with DB query only in the action method. But is there a way to accomplish fetching only what is needed with one JSF page and one managed bean?