Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating Dropdown Box using AJAX with JSF/Primefaces
    text
    copied!<p>I am trying to create a simple dropdown box using Ajax and JSF 2.0/primeface. Based on First Dropdown selection second dropdown box is populated using AJAX call.</p> <p>When I select first drop down it correctly populated the second dropdown box based on the Ajax call. But When I make selection in the second dropdown and click the button {which basically submit the form for some action}, It give error message "formViewBusinessCode:selectedBusinessCode: Validation Error: Value is not valid"</p> <p>When I check in console that is says the value for "selectedBusinessCode"{Id of second dropdown} is null. I am puzzled becuase it populates correctly but only after selection it gives error that value is not valid (basically null), Why the selected value is not reaching to the bean? Can someone please point what I am missing here, TIA</p> <p>xhtml code is as below</p> <pre><code>&lt;h:outputText styleClass="outputText" value="#{constant.businessCodeGroup}"&gt;&lt;/h:outputText&gt; &lt;h:selectOneMenu id="selectedBusinessCodeGroup" value="#{viewBusinessCodeBean.selectedBusinessCodeGroup}" &gt; &lt;f:selectItem itemValue="SELCT" itemLabel="Select Business Code Group" /&gt; &lt;f:selectItems value="#{viewBusinessCodeBean.businessCodeGroupList}" /&gt; &lt;p:ajax listener="#{viewBusinessCodeBean.getOnlyBusinessCodeListByAjaxCall}" event="change" update="selectedBusinessCode" process="@this"/&gt; &lt;/h:selectOneMenu&gt; &lt;h:outputText styleClass="outputText" value="#{constant.businessCode}"&gt;&lt;/h:outputText&gt; &lt;h:selectOneMenu id="selectedBusinessCode" value="#{viewBusinessCodeBean.selectedBusinessCode}"&gt; &lt;f:selectItem itemValue="SELCT" itemLabel="Select Business Code" /&gt; &lt;f:selectItems value="#{viewBusinessCodeBean.businessCodeList}" itemLable="#{viewBusinessCodeBean.businessCodeList.getlable}" itemValue="#{viewBusinessCodeBean.businessCodeList.getValue}" /&gt; &lt;/h:selectOneMenu&gt; &lt;h:commandButton value="View" action="#{viewBusinessCodeBean.getOnlyBusinessCodeDescription}"&gt;&lt;/h:commandButton&gt; </code></pre> <p>The bean coding is as below. it is a @ManagedBean</p> <p>To Populate First Dropdown box</p> <pre><code>public ViewBusinessCodeBean() { logger.entering(CLASS_NAME); this.businessCodeGroupList = new ArrayList&lt;SelectItem&gt;(); List&lt;String&gt;tempBusinessCodeList = new BusinessCodeTableServices().getBusinessCodeGroupList(); Iterator&lt;String&gt;iterator = tempBusinessCodeList.iterator(); while(iterator.hasNext()){ String businessCodeGroup = iterator.next(); logger.debug(businessCodeGroup); SelectItem item = new SelectItem(businessCodeGroup); businessCodeGroupList.add(item); } logger.exiting(CLASS_NAME); } </code></pre> <p>Ajax Call Method which populated second dropdown</p> <pre><code>public void getOnlyBusinessCodeListByAjaxCall() { this.businessCodeList = new ArrayList&lt;SelectItem&gt;(); List&lt;String&gt;tempBusinessCodeList = new BusinessCodeTableServices().getOnlyBusinessCodeList(getSelectedBusinessCodeGroup()); Iterator&lt;String&gt;iterator = tempBusinessCodeList.iterator(); while(iterator.hasNext()){ String businessCode = iterator.next(); SelectItem item = new SelectItem(businessCode,businessCode,businessCode); businessCodeList.add(item); } } </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