简体   繁体   English

根据selectonemenu值的更改更新另一个组件

[英]Update another component based on a change in the selectonemenu value

We are using JSF 1.2 for our project. 我们正在为项目使用JSF 1.2。 Requirement is to update another selectonemenu options based on a value change in the current selectonemenu. 要求是根据当前selectone菜单中的值更改来更新另一个selectonemenu选项。

Based on select1 option, select2 needs to be updated. 基于select1选项,需要更新select2。

<h:selectOneMenu id="select1" value="#{subscription.subscriptions}" onchange="javascriptMethod()">
    <f:selectItem id="item1" itemLabel="News" itemValue="1" />
    <f:selectItem id="item2" itemLabel="Sports" itemValue="2" />        
</h:selectOneMenu>

<h:panelGroup id="panel2">
 <h:selectOneMenu id="select2" value="#{subscription.subscriptions2}">
    <f:selectItem id="item1" itemLabel="News" itemValue="1" />
    <f:selectItem id="item2" itemLabel="Sports" itemValue="2" />        
</h:selectOneMenu>
</h:panelGroup>

You can use ajax support like this 您可以像这样使用ajax支持

  <h:selectOneMenu id="select1" value="#{subscription.subscriptions}"   >
    <f:selectItem id="item1" itemLabel="News" itemValue="1" />
    <f:selectItem id="item2" itemLabel="Sports" itemValue="2" />  


 </h:selectOneMenu>  

Jsf 1.2 doesn't have ajax support the only thing you can do is full page reload which happens on a command button. Jsf 1.2没有ajax支持,您唯一可以做的就是在命令按钮上进行整页重新加载。

I presumed you are using richfaces as a third party for ajax and rich ui components. 我假设您正在使用richfaces作为ajax和rich ui组件的第三方。 Hope this helps. 希望这可以帮助。

If you are using primefaces then you can replace tag with like this 如果您使用的是primefaces,则可以这样替换标签

<p:ajax event="onchange" update="select2" action="if you want to anything in   
                                                                      backend"/>   

If you want to do by javascript then have a hidden h:commandButton and put code in your 如果您想通过javascript进行操作,请隐藏h:commandButton并将代码放入
javascriptMethod() method like this 像这样的javascriptMethod()方法

     document.getElementById("myHiddenButtonId").click();  

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

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