Note that there are some explanatory texts on larger screens.

plurals
  1. POPrimefaces DataTable doesn't update the display value with a drop box, if the value attribute of <p:selectOneMenu> and <h:outputText> is different
    primarykey
    data
    text
    <p>I have a dataTable using Primefaces 3.5 as shown <a href="https://i.stack.imgur.com/pjjhO.png" rel="nofollow noreferrer">below</a>.</p> <p><img src="https://i.stack.imgur.com/pjjhO.png" alt="enter image description here"></p> <p>Now I'm editing the second row with the id 43 as shown in the following <a href="https://i.stack.imgur.com/bE21D.png" rel="nofollow noreferrer">image</a>.</p> <p><img src="https://i.stack.imgur.com/bE21D.png" alt="enter image description here"></p> <p>When I click the tick (the right most column), the row is edited as can be seen in the following <a href="https://i.stack.imgur.com/S5SjO.png" rel="nofollow noreferrer">picture</a>.</p> <p><img src="https://i.stack.imgur.com/S5SjO.png" alt="enter image description here"></p> <p>It can easily noticed that the name of the state is changed from <code>xxxx</code> to <code>zzz</code> but the country appears to remain the same which is expected to be updated to <code>America</code> from <code>Germany</code>.</p> <p>Actually, the changes have been made to the database but they don't seem to be reflected to the dataTable on completion of the <code>rowEdit</code> event.</p> <p>To observe the change made to the country, the page is required to be reload. Only when this page is reloaded, it displays the correct data as shown <a href="https://i.stack.imgur.com/bLrzr.png" rel="nofollow noreferrer">below</a>.</p> <p><img src="https://i.stack.imgur.com/bLrzr.png" alt="enter image description here"></p> <hr> <p>This is the column in which the country drop box is listed.</p> <pre><code>&lt;p:ajax event="rowEdit" listener="#{stateManagedBean.onRowEdit}" update=":form:dataTable :form:systemMessages :form:messages" process=":form:dataTable :form:systemMessages :form:messages"/&gt; &lt;p:ajax event="rowEditCancel" listener="#{stateManagedBean.onRowEditCancel}" update=":form:systemMessages :form:messages" process=":form:systemMessages :form:messages"/&gt; &lt;p:column headerText="Country" sortBy="#{state.country.countryName}" filterBy="#{state.country.countryName}" filterMaxLength="45"&gt; &lt;p:cellEditor&gt; &lt;f:facet name="output"&gt; &lt;h:outputText value="#{state.country.countryName}" /&gt; &lt;/f:facet&gt; &lt;f:facet name="input"&gt; &lt;p:selectOneMenu id="cmbCountryMenu" value="#{state.country.countryId}" rendered="true" editable="false" converter="#{longConverter}" converterMessage="The supplied value is incorrect." required="true" requiredMessage="Select an appropriate option." style="width:100%;"&gt; &lt;f:selectItems var="country" value="#{stateManagedBean.countries}" itemLabel="${country.countryName}" itemValue="${country.countryId}" itemLabelEscaped="true" rendered="true"/&gt; &lt;/p:selectOneMenu&gt; &lt;/f:facet&gt; &lt;/p:cellEditor&gt; &lt;/p:column&gt; </code></pre> <p>And the following is the <code>onRowEdit()</code> method (in JSF managed bean) which is triggered when the tick is clicked.</p> <pre><code>public void onRowEdit(RowEditEvent event) { StateTable stateTable=(StateTable) event.getObject(); if(stateService.update(stateTable)) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Success : ", "The row with the id "+stateTable.getStateId()+" has been updated successfully."); FacesContext.getCurrentInstance().addMessage(null, message); } } </code></pre> <p>The full code of <a href="http://pastebin.com/GRV8evZE" rel="nofollow noreferrer">JSF managed bean</a> and <a href="http://pastebin.com/SLJS1Pds" rel="nofollow noreferrer">JSF page</a>.</p> <hr> <p>In the <code>rowEdit()</code> method (as above), <code>stateTable.getCountry().getCountryId()</code> displays the updated <code>countryId</code> but using this country object to refer to the corresponding country name like <code>stateTable.getCountry().getCountryName()</code> just displays the old country name (not the updated one). What is the way to get around this?</p> <hr> <p><strong>Important:</strong></p> <p>In the XHTML code snippet above, the value attribute of both,</p> <pre><code>&lt;h:outputText value="#{state.country.countryName}"/&gt; ^^^^^^^^^^^^^_^^^^^^^^^^^ &lt;p:selectOneMenu id="cmbCountryMenu" value="#{state.country.countryId}" .../&gt; ^^^^^^^^^^^^^_^^^^^^^^^ </code></pre> <p>is different which is essential to display country names instead of displaying country ids and referring to the corresponding country ids.</p> <p>If they are changed to reflect the same <code>value</code> attribute,</p> <pre><code>&lt;h:outputText value="#{state.country.countryId}"/&gt; ^^^^^^^^^^^^^_^^^^^^^^^ &lt;p:selectOneMenu id="cmbCountryMenu" value="#{state.country.countryId}" .../&gt; ^^^^^^^^^^^^^_^^^^^^^^^ </code></pre> <p>then it works as expected (Primefaces showcase example(s) demonstrate(s) just like this).</p> <hr> <p>It is the same as updating a footer value dynamically showing the total of numeric values of a column. The footer is not updated while updating a row in that column. The issue has been reported <a href="https://code.google.com/p/primefaces/issues/detail?id=1558" rel="nofollow noreferrer">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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