br.com.jarch.faces.converter.PickListMigratedConverter Maven / Gradle / Ivy
package br.com.jarch.faces.converter;
import br.com.jarch.core.migration.Migrated;
import org.primefaces.component.picklist.PickList;
import org.primefaces.model.DualListModel;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import java.util.Iterator;
@FacesConverter(value = "pickListMigratedConverter")
public class PickListMigratedConverter implements Converter {
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
Object ret = null;
if (arg1 instanceof PickList) {
Object dualList = ((PickList) arg1).getValue();
DualListModel dl = (DualListModel) dualList;
for (Iterator iterator = dl.getSource().iterator(); iterator.hasNext(); ) {
Object o = iterator.next();
String id = (new StringBuilder()).append(o).toString();
if (arg2.equals(id)) {
ret = o;
break;
}
}
if (ret == null) {
for (Iterator iterator1 = dl.getTarget().iterator(); iterator1.hasNext(); ) {
Object o = iterator1.next();
String id = (new StringBuilder()).append(o).toString();
if (arg2.equals(id)) {
ret = o;
break;
}
}
}
}
return ret;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
String str = "";
if (value instanceof Migrated) {
str = value.toString();
}
return str;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy