0

I am developing a JSF 2.0 application, where I have an xhtml page with 4 cascading drop-downs. The drop-downs gets populated from the database based on some queries. That works well! Now I need to clear/reset these drop-downs after my selections are done. When I come to this page for a second time, the drop-downs still remain populated. If I select from the first drop-down, the second drop-down gets refreshed, but not the third and fourth. The data in those still remains intact. Here is the code I am using. I am just showing the 3 drop-downs here, the fourth is similar. Any help/suggestions appreciated.

<label class="control-label">Dropdown1</label>
<div>
<h:selectOneMenu id="drop1" value="#{myBean.aId}">
    <f:selectItem itemLabel="Select" itemValue="" />
    <f:selectItems value="#{myBean.aList}" var ="a"
                    itemLabel="#{a.name}"
                    itemValue="#{a.id}" />

    <p:ajax update="drop2" listener="#{myBean.populateDrop2}" />  

</h:selectOneMenu>
</div>         

<label class="control-label">Dropdown2</label>
<div>
<h:selectOneMenu id="drop2" value="#{myBean.bId}">
    <f:selectItem itemLabel="Select" itemValue="" />
    <f:selectItems value="#{myBean.bList}" var ="b"
                    itemLabel="#{b.name}"
                    itemValue="#{b.id}" />

    <p:ajax update="drop3" listener="#{myBean.populateDrop3}" />  

</h:selectOneMenu>
</div>   


<label class="control-label">Dropdown3</label>
<div>
<h:selectOneMenu id="drop3" value="#{myBean.cId}">
    <f:selectItem itemLabel="Select" itemValue="" />
    <f:selectItems value="#{myBean.cList}" var ="c"
                    itemLabel="#{c.name}"
                    itemValue="#{c.id}" />
</h:selectOneMenu>
</div>   
mona
  • 6,079
  • 12
  • 41
  • 46
  • Add all the components you want/need to update after an ajax request. In this case, you should have `` and make sure you clean the selected element from both dropdownlists. If you have `drop4`, `drop5` and on, you should clean all of them too. – Luiggi Mendoza Mar 15 '13 at 23:33

1 Answers1

1

That will happen if your bean is in the session scope, or if you navigated by a postback on the same view. Just put the bean in the view scope and navigate by a GET request. A view scoped bean lives as long as you interact with the same view by postbacks and a GET request will effectively create a fresh new view scoped bean.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555