0

We are using JSF 1.2 for our project. Requirement is to update another selectonemenu options based on a value change in the current selectonemenu.

Based on select1 option, select2 needs to be updated.

<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>
user679526
  • 845
  • 4
  • 16
  • 39

1 Answers1

0

You can use ajax support like this

  <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.

I presumed you are using richfaces as a third party for ajax and rich ui components. Hope this helps.

If you are using primefaces then you can replace tag with like this

<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
javascriptMethod() method like this

     document.getElementById("myHiddenButtonId").click();  
Srikanth Ganji
  • 1,127
  • 1
  • 13
  • 29