The solution :

write a converter like this in a webapp.converter package :
package fr.crb.stocks.webapp.converter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;
import org.appfuse.service.GenericManager;

import fr.crb.stocks.model.Localisation;

public class LocalisationConverter extends StrutsTypeConverter {
         
        private GenericManager<Localisation, Long> localisationManager;

        public void setLocalisationManager(GenericManager<Localisation, Long>
localisationManager) {
                this.localisationManager = localisationManager;
        }
    public Object convertFromString(Map context, String[] values, Class
toClass) {
        Localisation t = null;
        if(values.length>1){
                List l = new ArrayList();
                for(int i=0;i<values.length;i++){
                        t= new Localisation();
                        t.setId(new Long(values[i]));
                        l.add(t);
                }
                return l;
        }
        else if(values.length==1){
                t= new Localisation();
                        t.setId(new Long(values[0]));
                return t;
        }
        else return null;
                 
    }
 
    public String convertToString(Map context, Object o) {
       Localisation t = (Localisation)o;
       return t.getId().toString();
    }
 }

then add an xwork-conversion.properties in src/main/ressources with :

fr.crb.stocks.model.Localisation=fr.crb.stocks.webapp.converter.LocalisationConverter
... others converters


Then you can write directly in your jsp :

<s:select key="article.localisation" headerKey="-1"
                                headerValue="Selectionner une localisation" 
list="localisations"
                                listKey="id" listValue="nom" required="true" 
theme="xhtml" />
                


-- 
View this message in context: 
http://www.nabble.com/Struts-2-type-converter-tf3375754s2369.html#a9395519
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to