1
votes

I am trying to build an interface with three different select in way that the first select will render the second, this second select will load data and after the user selects an option from the second select, this will render the third that will load its data waiting for the user to select the final option.

After debugging and trying to solve this problem I see the last method is being called using an empty value, I guess it's because the bean is request scoped and after the AJAX request is destroyed. How could I work around this problem without making several calls to the DB and using a non-session-scoped-bean?

<h:selectOneMenu value="#{RequestBean.firstSelectValue}" id="first">
  <f:selectItem id="default" itemLabel="Select one" itemValue="-1" />
  <f:selectItems value="#{RequestBean.firstSelectElements}" 
                 var="var" itemLabel="#{var.label}"
                 itemValue="#{var.value}" />
  <f:ajax event="change" render="second" onevent="selectListener"/>
</h:selectOneMenu>

<h:selectOneMenu value="#{RequestBean.secondSelectValue}" id="second">
  <f:selectItem id="default" itemLabel="Select one" itemValue="-1" />
  <f:selectItems value="#{RequestBean.secondSelectElements}" 
                 var="var" itemLabel="#{var.label}"
                 itemValue="#{var.value}" />
  <f:ajax event="change" render="third" onevent="selectListener/>
</h:selectOneMenu>

<h:selectOneMenu value="#{RequestBean.third SelectValue}" id="third">
  <f:ajax event="change" render="someTextArea" onevent="selectListener" />
  <f:selectItem id="default" itemLabel="Select one" itemValue="-1" />
  <f:selectItems value="#{RequestBean.getThirdSelectElements(RequestBean.secondSelectValue)}" 
                 var="var" itemLabel="#{var.label}"
                 itemValue="#{var.value}" />
</h:selectOneMenu>
1

1 Answers

1
votes

Just put the bean in the view scope. It'll live as long as you're interacting with the same view by ajax.

See also: