Help with listshuttle
bryan_1983 Jul 15, 2009 7:46 PMHello!!!
I want to use a listshuttle to display information about users. All works fine, but when I select a user the property targetValue doesn't return the list of values.
This is the code of my listshuttle:
<rich:listShuttle sourceValue="#{obtenerContactos.source}"
id="listShuttleContactos" var="usuario"
sourceCaptionLabel="Contactos Disponibles:"
targetCaptionLabel="Contactos Seleccionados:"
targetValue="#{obtenerContactos.target}" showButtonLabels="false"
fastOrderControlsVisible="false" orderControlsVisible="false"
topControlLabel="Primero" copyAllControlLabel="Copiar Todos"
copyControlLabel="Copiar" downControlLabel="Bajar"
upControlLabel="Subir" removeAllControlLabel="Eliminar Todos"
removeControlLabel="Eliminar" bottomControlLabel="Último"
converter="contacto_converter">
this is my java class:
@Name("obtenerContactos")
@Scope(ScopeType.SESSION)
public class obtenerContactosLibretaDirecciones {
@In
EntityManager entityManager;
@In
Nmusuario user;
private String filtro;
Nmcontacto nmcontacto;
Nmusuario nmusuario;
private List<Nmcontacto> source;
private List<Nmcontacto> target;
@Create
public void constructor() {
try {
nmusuario = entityManager.find(Nmusuario.class, user.getIdContacto());
source = (nmusuario.getNmcontactos() == null) ? new ArrayList<Nmcontacto>(): new ArrayList<Nmcontacto>(nmusuario.getNmcontactos());
target = new ArrayList<Nmcontacto>();
} catch (Exception e) {
// TODO: handle exception
}
}
public List<Nmcontacto> getSource() {
return source;
}
public void setSource(List<Nmcontacto> source) {
this.source = source;
}
public List<Nmcontacto> getTarget() {
return target;
}
public void setTarget(List<Nmcontacto> target) {
this.target = target;
}
public String getFiltro() {
return filtro;
}
public void setFiltro(String filtro) {
this.filtro = filtro;
}
public void cadenaContactos(){
/*List<String> cadena = new ArrayList<String>();
for (int i = 0; i < target.size(); i++) {
cadena.add(target.get(i).getNombre().toString());
}
System.out.println(cadena);*/
System.out.println("target:"+this.target);
}
}
and this is my converter class:
@Name("contacto_converter")
@Converter(forClass=Nmcontacto.class)
public class contactoConverter implements javax.faces.convert.Converter{
@In EntityManager entityManager;
@In FacesMessages facesMessages;
public Object getAsObject(FacesContext context, UIComponent component, String value)throws ConverterException {
try {
Nmcontacto contacto=(Nmcontacto)entityManager.createQuery("from Nmcontacto m where m.nombre = :valor")
.setParameter("valor", value) .getSingleResult();
return contacto;
} catch (Exception e) {
facesMessages.add(e.getMessage());
return null;
}
}
public String getAsString(FacesContext context, UIComponent component, Object object)throws ConverterException {
try {
if (!(object instanceof Nmcontacto))
throw new ConverterException();
String res=((Nmcontacto)object).getNombre();
return res;
} catch (Exception e) {
facesMessages.add(e.getMessage());
return null;
}
}
}
I would thank that anybody explain me how resolve my problem.
Regards.