1

I have a JSF page that contains a form with several elements, that correspond to different configurable attributes that the user can select, say

<h:form> 
  <h:selectManyCheckbox value="#{bean.p}">
         <f:selectItem itemLabel="p1" itemValue="1" />
         <f:selectItem itemLabel="p2" itemValue="2" />
         <f:ajax render="panel1" />
  </h:selectManyCheckbox>

  <h:selectManyCheckbox value="#{bean.t}">
         <f:selectItem itemLabel="t1" itemValue="1" />
         <f:selectItem itemLabel="t2" itemValue="2" />
         <f:ajax render="panel1" />
  </h:selectManyCheckbox>

  <h:panelGroup id="panel1">....</h:panelGroup>
</h:form>

My problem is that the moment the user selects a value for p, I lose the values stored for t in the bean and so the other way around.

I need this information to create a query that returns the results I display in panel1, but at the moment I can only base this query on one parameter or the other.

Any help much appreciated

glasspill
  • 1,290
  • 4
  • 21
  • 36

1 Answers1

0

The managed bean is apparently in the request scope. A request scoped bean instance ends its life by end of the HTTP request/response cycle. Every ajax request thereafter on the same view accounts as a brand new HTTP request and will thus create a brand new bean instance with all properties set to default. You need to put the bean in the view scope in order to keep it alive as long as you're interacting with the same view.

@ManagedBean
@ViewScoped
public class Bean {
    // ...
}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555