[英]nested SelectOneMenu JSF 2.1
I am developing a web application using JSf2.1. 我正在使用JSf2.1开发Web应用程序。 I am following tutorials to code a selectOneMenu (drop down list box).
我正在按照教程编写selectOneMenu(下拉列表框)代码。
I need to have 2 dropdown boxes(A ad B) but essentially call the same ajax listener function which would do some computation with the choice A and B... 我需要有2个下拉框(A ad B),但实际上调用了相同的Ajax侦听器函数,该函数将使用选择A和B进行一些计算...
So, can we have nested selectOneMenu like this? 那么,我们可以像这样嵌套selectOneMenu吗?
<h:form id= "ourForm">
<h:selectOneMenu value= "#{bean.valA}"...>
<f:selectItems ... />
<h:selectOneMenu value= "#{bean.valB}"...>
<f:selectItems ... />
<f:ajax listener="#{bean.listener}" render="ourForm"/>
</h:selectOneMenu>
</h:selectOneMenu>
</h:form>
And the bean listener method: 和bean侦听器方法:
public void Listener{
//use valA and valB
}
Well, I tried doing the above but the page shows me a warning: 好吧,我尝试执行上述操作,但页面显示警告:
the form component needs to have a UIForm in its ancestry.Suggestion enclose the necessary withing 表单组件的祖先需要有一个UIForm。建议将必要的附带
I tried without the nesting by calling the same listener on each selectOneMenu but I get same random behaviour..ie: when I choose elem 1 of A retaining the "prev" choice on B, box B randomly updates its choice to default and vice versa! 我尝试通过在每个selectOneMenu上调用相同的侦听器而没有嵌套,但是得到了相同的随机行为..ie:当我选择A的元素1保留B上的“上一个”选项时,Box B随机将其选择更新为default,反之亦然!
Please advise. 请指教。
This is invalid syntax. 这是无效的语法。 You need to understand that JSF generates HTML code.
您需要了解JSF会生成HTML代码。 A
<h:selectOneMenu>
generates a <select><option/></select>
. <h:selectOneMenu>
生成一个<select><option/></select>
。 A nested <h:selectOneMenu>
as in your attempt would generate <select><option/><select><option/></select></select>
which is completely invalid HTML (and thus inherently also completely invalid JSF). 像您尝试的那样,嵌套的
<h:selectOneMenu>
会生成<select><option/><select><option/></select></select>
,这完全是无效的 HTML(因此,本质上也是完全无效的JSF)。
You're not terribly clear on the concrete functional requirement, but I understand that you want to show a child menu only on certain selection of a parent menu? 您对具体的功能要求并不十分清楚,但是我知道您只想在选择父菜单时才显示子菜单? In that case, use the
rendered
attribute and refer it in <f:ajax render>
. 在这种情况下,请使用
rendered
属性,并在<f:ajax render>
引用它。
Here's a rough kickoff example, which can if necessary be more simplified (eg without the need for renderMenuB
property, depending on the concrete functional requirement which you didn't tell anything about). 这是一个粗略的启动示例,可以在必要时对其进行简化(例如,不需要
renderMenuB
属性,具体取决于具体的功能要求,而您对此一无所知)。
<h:selectOneMenu value="#{bean.selectedValueA}">
<f:selectItems value="#{bean.availableValuesA}" />
<f:ajax listener="#{bean.handleChangeA}" render="menuB" />
</h:selectOneMenu>
<h:panelGroup id="menuB">
<h:selectOneMenu value="#{bean.selectedValueB}" rendered="#{bean.renderMenuB}">
<f:selectItems value="#{bean.availableValuesB}" />
<f:ajax listener="#{bean.handleChangeB}" render="ourForm" />
</h:selectOneMenu>
</h:panelGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.