我有一个 jsf 页面,其中有一个 selectOneMenu 并且,我想在 selectOneMenu 更改时打开一个对话框。
As a example if user selects a value ="passive" from jsf selectOneMenu it should open a dialog box or a light box on same page where I want to display a small jsf form like as here done.(please click on that small image(yes, like this dialog box I want to open after selecting particular value in selectOneMenu) ) http://www.primefaces.org/showcase-labs/ui/dialogLogin.jsf
我还想将提交的数据保存在我的支持 bean 中的某个地方,以便稍后将其存储到数据库中。
我不知道如何在同一窗口中从支持 bean 打开对话框或灯箱,因为我们将使用 valueChangeListener 事件或使用 ajax 事件来识别值更改。
我能够识别从 selectOneMenu(DropdownMenu) 中选择了哪个值,但不知道如何打开选择特定值的对话框。
<h:outputLabel
value="* Country: "/>
<h:selectOneMenu
id="someSelect"
value="#{testController.countryName}"
required="true">
<f:selectItem
itemLabel="Select Country"
itemValue=""/>
<f:selectItems
value="#{testController.countryNamesSelectItems}"/>
</h:selectOneMenu>
假设我们在 selectItems 中有 2 个选项作为 India 和 Austrlia,那么如果用户选择 India 应在同一页面上打开一个对话框,用户需要在其中填写一些信息并需要提交 如果他来自印度(比如这里的例子http://www.primefaces.org/showcase-labs/ui/dialogLogin.jsf(请点击那个小图片(是的,就像这个对话框我想在选择特定的后打开 selectOneMenu 中的值) )用户将输入他的用户名和密码并提交数据)
希望对你有帮助
how can we check in primefaces , selected value of selectOneMenu using java script(jquery) like done here for richfaces t:selectOneMenu how to get selected value using java script??
最佳答案
您可以使用 h:selectOneMenu
的 onchange
属性打开对话框:
<h:selectOneMenu
id="someSelect"
value="#{testController.countryName}"
required="true"
onchange="dlg.show()">
将 dlg
作为 p:dialog
的 widgetVar
属性的值。这将在服务器被访问之前打开对话框。
如果您想在 ajax 请求完成后打开对话框,您可以使用带有 oncomplete
属性的 p:ajax
:
<p:ajax update=".." process=".." oncomplete="dlg.show()"/>
或者,如果您想根据所选值打开对话框,您可以使用包装函数:
function showDialog() {
if($('#IdOfYourSelectOneMenu').val() == 'India') {
dlg.show();
}
}
与:
<p:ajax update=".." process=".." oncomplete="showDialog()"/>
关于javascript - 在 selectOneMenu 更改时在同一窗口中打开对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10863426/