0

Here is an example of what I am trying to do.

In the sessionScoped bean

SessionBeanloadRecord(){
Do something
ViewScopedBean viewScopedBean = (ViewScopedBean) context.getApplication().evaluateExpressionGet(context, "#{viewScopedBean}", ViewScopedBean.class);
return viewScopedBean.viewScopedBeanLoadRecord();
}

In the viewScoped bean

ViewScopedBeanloadRecord(){
Retrieve and populateFields    
return "viewRecord.xhtml";    
}

So in a nut shell I would like to call a method within a view scoped bean from another bean which is on another view (listRecords.xhtml). When I run this (just using a standard commandlink), the session bean works as I would expect, viewScoped bean is created and the ViewScopedBeanloadRecord method is called BUT THEN the viewScoped bean is recreated (the constructor is called again) but this time the ViewScopedBeanloadRecord is not run and the page loads with blank fields.

I understand that the view scoped bean is only alive as long as you return null (or have a void method) to stay on the same view but then how do you transition from listRecords.xhtml to viewRecord.xhtml and run the load method?

Once I am on the viewRecord.xhtml view I will also be required to load more records simultanously (in different browser windows) so I cannot keep the records in the session.

Please note: Based on company policy I am not allowed to post actual code so this example is what I am limited to. Sorry!

Any help would be appreciated!

Thanks

Eric

4

2 回答 2

0

We had a similar problem and we have solved it by using a @SessionScoped bean as a backing bean for the whole session. We inject it in other @ViewScoped and @RequestScoped beans managing the needed data in session.

Another walk around would be to use GET parameters.

Remember about the Life Cycle of beans, and use different functions for the purpose of polluting with data. @PostConstruct annotation comes very handy too.

Good luck :)

于 2012-08-14T08:20:01.447 回答
0

After fighting and trying different combinations with Requestscoped, Viewscoped and @PostConstruct I was unable to get this scenario to work properly. I am also using dynamic include files which depend on properties in the beans to decide which xhtml file to build, this seemed to cause a problem when using the viewScope and @PostConstruct.

So I went with an entirely session based solution.

Instead of a viewScoped or requestScoped bean I created a property of type "record" within the session bean and whenever the view record method in the sessionbean was called I replaced the previous record property with the new one and then forward to the display record view. So it created a sort of "request" record property that was overwritten with each new call to the view record method. So only the last recored viewed stays in the session.

I have read about the <t:saveState> tag which might solve the issue but as a project it was decided to not use any additional frameworks on top of JSF so that was not an option.

于 2012-08-14T19:38:18.910 回答