Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not sure if this is the way you want to go about for this. But you can load the Department list base on the selection of Product. To do this you need to send Ajax request to update the Department list when you select a Product. To illustrate this, I will use PrimeFaces to send out ajax request</p> <pre><code>&lt;h:selectOneMenu id="product" value="#{bean.selectedProduct}"&gt; &lt;f:selectItem itemLabel="Select Product" itemValue="" /&gt; &lt;f:selectItems value="#{bean.productList}"/&gt; &lt;!-- here is where I send out ajax request --&gt; &lt;p:ajax listener="#{bean.loadDepartmentById}" event="change" update="department" /&gt; &lt;/h:selectOneMenu&gt; &lt;h:selectOneMenu id="department" value="#{bean.selectedDepartment}"&gt; &lt;f:selectItem itemLabel="" itemValue="" /&gt; &lt;f:selectItems value="#{bean.departmentList}"/&gt; &lt;/h:selectOneMenu&gt; </code></pre> <p>Here is my bean</p> <pre><code>@ManagedBean @ViewScoped public class bean{ private List&lt;SelectItem&gt; productList = null; private List&lt;SelectItem&gt; departmentList = null; private Long selectedProduct = null; private Long selectedDepartment = null; @PostConstruct public void init(){ //Pre load product list productList = new ArrayList&lt;SelectItem&gt;(); productList.add(new SelectItem("value1", "label1")); productList.add(new SelectItem("value2", "label2")); productList.add(new SelectItem("value3", "label3")); //The values are the keys passed to the selectItem property. //The labels are those what you see on the menu. } public void loadDepartmentById(){ if(selectedProduct != null){ //Load the appropriate list of department. } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload