com.github.adminfaces.persistence.converter.EntityConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of admin-persistence Show documentation
Show all versions of admin-persistence Show documentation
Provides CRUD utilities for CDI, JPA and JSF based applications.
package com.github.adminfaces.persistence.converter;
import com.github.adminfaces.persistence.model.PersistenceEntity;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
@FacesConverter(forClass = PersistenceEntity.class, value = "entityConverter")
public class EntityConverter implements Converter {
@Override
public String getAsString(FacesContext context, UIComponent component, Object entity) {
if (entity == null || "".equals(entity)) {
return null;
}
if (!getEntityMap(context).containsKey(entity)) {
String uuid = UUID.randomUUID().toString();
getEntityMap(context).put(entity, uuid);
return uuid;
} else {
return getEntityMap(context).get(entity);
}
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String uuid) {
Set> entries = getEntityMap(context).entrySet();
for (Entry
© 2015 - 2024 Weber Informatics LLC | Privacy Policy