Note that there are some explanatory texts on larger screens.

plurals
  1. POselected item in selectonemenu is always null
    text
    copied!<p>I am trying to use a <code>&lt;p:dataTable&gt;</code> to display the contents of an object selected from a <code>&lt;p:selectOneMenu&gt;</code> list.</p> <p>The <code>&lt;p:selectOneMenu&gt;</code> is correctly populated with options. However:</p> <ol> <li>The <code>&lt;p:dataTable&gt;</code> is not updated when I select an item from the <code>&lt;p:selectOneMenu&gt;</code></li> <li>The server log indicates that the value of <code>#{MB.selectedDatabase}</code> is <code>null</code>. </li> <li><code>#{MB.setSelectedDatabase()}</code> is never invoked. </li> </ol> <p><strong>XHTML:</strong> </p> <pre class="lang-xml prettyprint-override"><code>&lt;h:form id="form"&gt; &lt;h:messages id="messages" /&gt; &lt;p:panelGrid columns="2"&gt; &lt;p:outputLabel value="Data:" /&gt; &lt;p:selectOneMenu immediate="true" id="customDatas" value="#{MB.selectedDatabase}" &gt; &lt;p:ajax execute="customDatas" render="infos" listener="#{MB.whatIsSelected()}" /&gt; &lt;f:selectItem itemLabel="Select Data" itemValue="" /&gt; &lt;f:selectItems value="#{MB.datas}" var="data" itemLabel="#{data.name}" itemValue="#{data.id}"/&gt; &lt;/p:selectOneMenu&gt; &lt;/p:panelGrid&gt; &lt;p:dataTable value="#{MB.selectedDatabase.infos}" var="item" id="infos" &gt; &lt;p:column &gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Info"/&gt; &lt;/f:facet&gt; &lt;h:outputText value="#{item.info}"/&gt; &lt;/p:column&gt; &lt;/p:dataTable&gt; &lt;/h:form&gt; </code></pre> <p><strong>Partial code from my sessionScoped Bean:</strong></p> <pre class="lang-java prettyprint-override"><code> public Data selectedDatabase; public void whatIsSelected(){ logger.log(Level.SEVERE, "Selected data is : {0}", selectedDatabase.getName()); infoBusinessLocal.getinfosbydata(selectedDatabase); } public Data getSelectedDatabase() { return selectedDatabase; } public void setSelectedDatabase(Data selectedDatabase) { logger.log(Level.SEVERE, "Set selectedDB is invoked"); this.selectedDatabase = selectedDatabase; } </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