开发者

JSF, How to set a property in a different page/backing bean and then navigate to that page?

I am using JSF 2.0 and attempting to pass values between different pages in my App.

The setup is as follows: I have a page called userSelect that has a backing bean userSelectBacking. On this page I display a list of users that can be selected and submit using an h:commandbutton, when the page is submit the navigation goes to a userEdit page.

I have a page called userEdit, that has a backing bean userEditBacking which displays the information for a user and allows that user to be edited.

I would like to pass the user selected from the userSelect page into the userEdit page. I am currently using f:setPropertyActionListener to set the user in my userEdit backing from the userSelect page, however when I navigate to the userEdit page, it loses the information I set.

is there a way that I can pass the values between the two pages/backing beans?开发者_开发问答

thanks


I am currently using f:setPropertyActionListener to set the user in my userEdit backing from the userSelect page

It should work.

however when I navigate to the userEdit page, it loses the information I set.

This will happen if the data loading logic is wrong, or you fire a redirect afterwards while the bean is request scoped.

To fix the data loading logic, just ensure that in case of a request scoped bean the same datamodel is preserved in the subsequent request. Usually you use the bean's constructor or lazy loading in the getter for this. If that is not an option, then you need to put the bean in a bit broader scope, e.g. @ViewScope or @SessionScope.

To fix the redirect issue, either just don't fire a redirect (i.e. remove <redirect/> from navigation case, or don't call ExternalContext#redirect()), or put bean in a broader scope.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜