jsf - primefaces autocomplete selection returns null -


autocomplete works fine, mean when write gets values db , autocompletes when select value, shows selectedparty null.by way using converter selectonemenu , works fine, can selected value there problem autocomplete component.
view;

<p:autocomplete id="partysearchautoid" value="#{mycontroller.selectedparty}"                                     var="party" itemlabel="#{party.partyname}"                                     itemvalue="#{party}" converter="genericconverter"                                     forceselection="true"                                                                             completemethod="#{mycontroller.searchparty}">                         <p:ajax event="itemselect" update="soainputtextid"/>                     </p:autocomplete> 

my controller;

    private party selectedparty;      public list<party> searchparty(string query) {        list<party> partylist = genericservice.getbytemplate(new party(), "partyname", query);       return partylist;   }  public party getselectedparty() {     return selectedparty; }  public void setselectedparty(party selectedparty) {     this.selectedparty = selectedparty; } 

here converter;

@facesconverter("genericconverter") public class genericconverter extends selectitemsconverter {  @override public string getasstring(facescontext context, uicomponent component, object value) {     return value.tostring(); }    @override public object getasobject(facescontext context, uicomponent component, string value) {     return super.getasobject(context, component, value); //to change body of generated  methods, choose tools | templates.  }    } 

use generic entity converter

package com.sfp.web.beans;

import java.util.map; import java.util.map.entry; import java.util.uuid; import java.util.weakhashmap;  import javax.faces.component.uicomponent; import javax.faces.context.facescontext; import javax.faces.convert.converter; import javax.faces.convert.facesconverter;  @facesconverter(value = "entityconverter") public class entityconverter implements converter {      private static map<object, string> entities = new weakhashmap<object, string>();      @override     public string getasstring(facescontext context, uicomponent component, object entity) {         synchronized (entities) {             if (!entities.containskey(entity)) {                 string uuid = uuid.randomuuid().tostring();                 entities.put(entity, uuid);                 return uuid;             } else {                 return entities.get(entity);             }         }     }      @override     public object getasobject(facescontext context, uicomponent component, string uuid) {         (entry<object, string> entry : entities.entryset()) {             if (entry.getvalue().equals(uuid)) {                  return entry.getkey();             }         }         return null;     } } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -