"primefaces picklist converter" Code Answer


for picklist use this generic converter :

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>();

    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);

    public object getasobject(facescontext context, uicomponent component, string uuid) {
        for (entry<object, string> entry : entities.entryset()) {
            if (entry.getvalue().equals(uuid)) {
                return entry.getkey();
        return null;

By SBJ on October 7 2022

Answers related to “primefaces picklist converter”

Only authorized users can answer the Search term. Please sign in first, or register a free account.