简体   繁体   English

多个h:selectOneMenu加载了f:ajax

[英]Multiple h:selectOneMenu loaded with f:ajax

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. 经过调试并尝试解决此问题后,我看到使用空值调用了最后一个方法,我想这是因为Bean被限制了请求范围,并且销毁了AJAX请求。 How could I work around this problem without making several calls to the DB and using a non-session-scoped-bean? 如何在不多次调用数据库和使用非会话范围的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>

Just put the bean in the view scope. 只需将bean放入视图范围即可。 It'll live as long as you're interacting with the same view by ajax. 只要您通过ajax与同一视图进行交互,它就会一直存在。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM