JSF2.0 State_Saving_Method client issues

2019-09-16 03:14发布

问题:

Im using Mojarra 2.1.3, Netbeans 7.0.1, primefaces 3.2.

I am currently in a quandary whether to use STATE_SAVING_METHOD client or server. Currently Im setting the saving method to client. And this involves me doing adjustment to seriazibility of many objects. And putting transient keyword on the stateless facade session beans.

@ManagedBean
@ViewScoped
public class SaProductController implements Serializable {
@EJB
transient SaProductFacade saProductFacade;
@EJB
transient SaKeywordFacade saKeywordFacade;
....

My xhtml page has a primefaces dataTable with pagination. The first time loading the page it works by showing the first page in the datatable. However, upon clicking on next page, this lines throws a NullPointerException error.

data = saProductFacade.selectAll(first, pageSize);

Why is that? Is it because saProductFacade @EJB property declared as transient and it's destroyed on postback to the same page. The ViewScoped managed bean is still alive anyway. Please help, how to solve this issue? Or am I doing it wrong?

For information, this works perfectly if I set the STATE_SAVING_METHOD to server. But the peril of the browser back button made me decide to go the client state saving option. And also, memory limitation on the server is warranting client state saving.

回答1:

Just for information, for beginners, Im using server state saving method now. And I use session variables to remember where am I if user press on back button. This way the ViewScoped backing bean is recreated and automatically paginate to the page where the user last viewed. So that I can redirect the user to where their last datatable page was before they navigate to another page using GET HTTP request.