jsf - Primefaces DataTable doesn't update the display value with a drop box, if the value attribute of <p:selectOneMenu> and <h:outputText> is different -


i have datatable using primefaces 3.5 shown below.

enter image description here

now i'm editing second row id 43 shown in following image.

enter image description here

when click tick (the right column), row edited can seen in following picture.

enter image description here

it can noticed name of state changed xxxx zzz country appears remain same expected updated america germany.

actually, changes have been made database don't seem reflected datatable on completion of rowedit event.

to observe change made country, page required reload. when page reloaded, displays correct data shown below.

enter image description here


this column in country drop box listed.

<p:ajax event="rowedit" listener="#{statemanagedbean.onrowedit}" update=":form:datatable :form:systemmessages :form:messages" process=":form:datatable :form:systemmessages :form:messages"/> <p:ajax event="roweditcancel" listener="#{statemanagedbean.onroweditcancel}" update=":form:systemmessages :form:messages" process=":form:systemmessages :form:messages"/>   <p:column headertext="country" sortby="#{state.country.countryname}" filterby="#{state.country.countryname}" filtermaxlength="45">                         <p:celleditor>         <f:facet name="output">             <h:outputtext value="#{state.country.countryname}" />         </f:facet>         <f:facet name="input">             <p:selectonemenu id="cmbcountrymenu" value="#{state.country.countryid}" rendered="true" editable="false" converter="#{longconverter}" convertermessage="the supplied value incorrect." required="true" requiredmessage="select appropriate option." style="width:100%;">                 <f:selectitems var="country" value="#{statemanagedbean.countries}"  itemlabel="${country.countryname}" itemvalue="${country.countryid}" itemlabelescaped="true" rendered="true"/>             </p:selectonemenu>         </f:facet>     </p:celleditor> </p:column> 

and following onrowedit() method (in jsf managed bean) triggered when tick clicked.

public void onrowedit(roweditevent event) {     statetable statetable=(statetable) event.getobject();      if(stateservice.update(statetable))     {         facesmessage message = new facesmessage(facesmessage.severity_info, "success : ",  "the row id "+statetable.getstateid()+" has been updated successfully.");         facescontext.getcurrentinstance().addmessage(null, message);     } } 

the full code of jsf managed bean , jsf page.


in rowedit() method (as above), statetable.getcountry().getcountryid() displays updated countryid using country object refer corresponding country name statetable.getcountry().getcountryname() displays old country name (not updated one). way around this?


important:

in xhtml code snippet above, value attribute of both,

<h:outputtext value="#{state.country.countryname}"/>                        ^^^^^^^^^^^^^_^^^^^^^^^^^ <p:selectonemenu id="cmbcountrymenu" value="#{state.country.countryid}" .../>                                               ^^^^^^^^^^^^^_^^^^^^^^^ 

is different essential display country names instead of displaying country ids , referring corresponding country ids.

if changed reflect same value attribute,

<h:outputtext value="#{state.country.countryid}"/>                        ^^^^^^^^^^^^^_^^^^^^^^^ <p:selectonemenu id="cmbcountrymenu" value="#{state.country.countryid}" .../>                                               ^^^^^^^^^^^^^_^^^^^^^^^ 

then works expected (primefaces showcase example(s) demonstrate(s) this).


it same updating footer value dynamically showing total of numeric values of column. footer not updated while updating row in column. issue has been reported here.

the problem not changing whole country object. because use #{state.country.countryid} value of p:selectonemenu property countryid of selected country changing, not country, i.e. other properties countryname remain.

you have change value of p:selectonemenu #{state.country} , itemvalue of f:selectitems #{country}. @ showcase p:selectonemenu.

additionally, country pojo no converter available default, have implement countryconverter , use conversion when selecting item via p:selectonemenu.

use following code p:selectonemenu , article support implementing converter.

<p:selectonemenu id="cmbcountrymenu" value="#{state.country}" rendered="true" editable="false" converter="#{countryconverter}" convertermessage="the supplied value incorrect." required="true" requiredmessage="select appropriate option." style="width:100%;">     <f:selectitems var="country" value="#{statemanagedbean.countries}"  itemlabel="#{country.countryname}" itemvalue="#{country}" itemlabelescaped="true" rendered="true"/> </p:selectonemenu> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -