ajax - Primefaces autocomplete (multiple), handle prepopulated items -


i have simple autocomplete (multiple) component (similar 1 in pf showcase), allowing users select items dropdown list, , commandbutton save values database.

@postconstruct method fetches data , prepopulates them (if found) in autocomplete component.

the problem component seems have no control prepopulated items. example, if delete 1 clicking close icon, disappears page, event object in neither valuechangelistener, selecteventlistener (ajax itemselect), nor unselecteventlistener (ajax unselect) returns correct value, instead return null. can add new item(s) or delete new added item(s). if delete 1 of prepopulated items, , click save, other prepopulated items gone.

how handle (delete) prepopulated items in autocomplete ?

pf version 5.2 

bean.java

private list<someobjs> selectedsomeobjs = new arraylist<>();  @postconstruct public void init() {     this.selectedsomeobjs = somedb.getsavedsomeobjs(); }  public void valuechange(valuechangeevent event) {     object oldval = event.getoldvalue(); // return prepopulated items     object newval = event.getnewvalue(); // return null, if delete 1 of prepupulated items } 

.xhtml

<p:autocomplete id="auto" multiple="true"             value="#{bean.selectedsomeobjs}"             completemethod="#{bean.autocomplete}" var="v"             itemlabel="#{v.desc}" itemvalue="#{v}" autocomplete="true" maxresults="15"             minquerylength="1" querydelay="100" forceselection="true" cache="true"             valuechangelistener="#{bean.valuechange}">     <o:converter converterid="omnifaces.listconverter" list="#{bean.objslist}"/>     <p:ajax event="itemunselect" listener="#{bean.selectlistener}"/>     <p:ajax event="itemselect" listener="#{bean.unselectlistener}"/> </p:autocomplete> 


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -