0

As we all know, when we render a component of the JSF web application, we will lose property value. We have two solutions:

  1. Set the ManagedBean type Session in face-config.xml
  2. Set property Of Managed Bean static type. E.x:

    Public static String txtName Ex.

I want to find a way not used the second way (so many they will only web browser access to a single static variable) and not to use a SessionBean like the 1st way.

Is there any solution to solve this problem?

Hung Phan Dang
  • 360
  • 1
  • 4
  • 20

1 Answers1

0

Just use the view scope. It's designed for exactly this purpose. Remembering the values responsible for the view state across ajax requests on the same view.

@ManagedBean
@ViewScoped
public class Bean {

    // ...

}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thank you so much for your suggestion. Can I define ViewScoped in face-config.xml like this: userBean com.demo.bean.UserBean view – Hung Phan Dang Aug 14 '12 at 21:00
  • Yes. How exactly does that fail for you? Or haven't you even tried it at all? In the future, please try before asking :) – BalusC Aug 14 '12 at 21:02
  • I tried over 20 times and it's still failed. The property value has been save but so unfortunately, the popup didn't show. I will show my demo error few minutes later – Hung Phan Dang Aug 14 '12 at 21:52
  • Apparently you're (implicitly) recreating the view everytime. Some code in flavor of an SSCCE would definitely help to spot the cause of the problem :) – BalusC Aug 14 '12 at 22:26
  • http://www.youtube.com/watch?v=FTvd1NrAjxU&feature=youtu.be Here is my web bug when I want to render a popup using viewScope in managed Bean – Hung Phan Dang Aug 15 '12 at 07:16
  • It's a nice video, but you're merely demonstrating/confirming the bug which you've already described in the question. The video did not show the full code in its entirety, let along in an SSCCE flavor, but I saw in an occassion in the video that you were using the `binding` attribute. That won't work in combination with the view scope due to JSF issue 1492. Get rid of the `binding` attributes or look for alternate ways. – BalusC Aug 15 '12 at 10:19
  • Oh thank you, I will try to make better videos in next time. I've change way to show popup, not use binding. But unfortunately it still bug :(, the bug is the same with the bug when i use binding. I will send you my project example soon :). I'm very glad to talk with you :) – Hung Phan Dang Aug 16 '12 at 14:53