myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Porryman <a.otero.and...@gmail.com>
Subject inputSuggest (non AjaX) with objects and converter
Date Tue, 05 Mar 2013 19:27:46 GMT
Hello!
I'd like to use the tag s:inputSuggest but to retrieve an Object not a
string. If a use a Map<String, String> its renders ok, however mi converter
is never invoke, and if I use a Map<Object, String> I get a
ClassCastException cause can't convert an object to a string. 
my jsp code is as follows :


<s:inputSuggest id="prueba2" required="true" converter="aparatoConverter"
value="#{clienteAparato.aparatoCA}">
                                            <f:selectItems
value="#{clienteAparato.selectMapAparatosCA}" />
                                            </s:inputSuggest>

Converter is:

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String
arg2) throws ConverterException {
        AparatoBO apBO=getAparatoBO();
        Aparato ap=apBO.getAparato(Integer.valueOf(arg2));
        return ap;
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object
arg2) throws ConverterException {
        if(arg2!= null){
        Aparato ap=(Aparato) arg2;
        return ap.getId()+"";
        }
        else return "";
        
    }

    private AparatoBO getAparatoBO(){
        return (AparatoBO) FacesContextUtils.
                getWebApplicationContext(FacesContext.getCurrentInstance()).
                getBean("aparatoBO");
    }

and bean code is:

    public Map getSelectMapAparatosCA(){
        Map aux=new HashMap();
        Iterator i=this.aparatoBO.getListaAparato().iterator();
        while(i.hasNext()){
            Aparato ap=(Aparato)i.next();
            aux.put(ap,ap.getModelo());
        }
        return aux;
    }

Aparato class atributes

public class Aparato implements Serializable{
    private int id;
    private String modelo;
    private long codBarras;
    private double precioVenta;
    private TipoAparato tipoAparato;
    private Marca marca;


Thank you very much in advance



--
View this message in context: http://myfaces.10567.n7.nabble.com/inputSuggest-non-AjaX-with-objects-and-converter-tp114348.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Mime
View raw message