Makoto
Makoto

Reputation: 775

how to reinitalize selected value of drop down lists when I come back to the page (Java server Faces)?

I use Java Server Faces and I have some beans. In my xhtml page, I display some drop down lists with the latest selected value at the top. I would like to know how to reinitialize the values when I quit the page (but not the session, by example, by clicking on another page of my web site) and come back to the first page), so that when I come back, my drop down list has the by default value at the top, not the selected one before I quit the page.

Should I put something in the bean constructor ?

The structure of the bean is

 @ManagedBean(name = "myBean", eager = true)
 @SessionScoped
 public class myBean implements Serializable {
      ....

     public myBean () {
          ...
     }

 }

Upvotes: 0

Views: 211

Answers (3)

Sarz
Sarz

Reputation: 1976

You can use onLoad function

<h:body onload="#{app.initilize()}">

where the code goes

    @ManagedBean(name = "app", eager = true)
    @SessionScoped
    public class MyApp {
        public void initilize() {
              ....
        }

Upvotes: 1

Smutje
Smutje

Reputation: 18163

I think the scope which applies more suitable to your bean is @RequestScoped (see http://docs.oracle.com/javaee/6/tutorial/doc/gjbbk.html).

Upvotes: 1

SJuan76
SJuan76

Reputation: 24895

Since your bean is @SessionScoped, it will only be instantiated once in the session. So, the constructor will be called once.

Use the value from a @RequestScoped or @ViewScoped bean, or set the value in your bean through the controller.

Do not forget to follow Java naming conventions (all classes names begin with uppercase).

Upvotes: 1

Related Questions