It might have to do with the way I contribute my Translator i.e.: * @Contribute(TranslatorSource.class)* * public static void provideTranslators(MappedConfiguration<Class, Translator> configuration){* * configuration.add(Postcode.class, new PostcodeTranslator());* * }*
See how I instanciate the PostcodeTranslator... I don't know how to get round this... Can someone please help? Regards, Julien. 2011/10/16 Julien Martin <bal...@gmail.com> > Hello, > I have the following Translator implementation: > > package com.bignibou.web.services; > > import com.bignibou.domain.Postcode; > import com.bignibou.service.BignibouService; > import org.apache.tapestry5.Field; > import org.apache.tapestry5.MarkupWriter; > import org.apache.tapestry5.Translator; > import org.apache.tapestry5.ValidationException; > import org.apache.tapestry5.ioc.annotations.Inject; > import org.apache.tapestry5.services.FormSupport; > > > > > public class PostcodeTranslator implements Translator<Postcode> { > > @Inject > BignibouService service; > > @Override > public String getName() { > return "postcodeTranslator"; > } > > @Override > public String toClient(Postcode value) { > return value.getPostcode(); > } > > @Override > public Class<Postcode> getType() { > return Postcode.class; > } > > @Override > public String getMessageKey() { > return "postcodeTranslator-parse-exception"; > } > > @Override > public Postcode parseClient(Field field, String clientValue, String > message) throws ValidationException { > try { > String[] postcodesIds = clientValue.split(","); > int postcodeId = Integer.parseInt(postcodesIds[0]); > return service.loadPostcodeById(postcodeId);*//NULL POINTER > EXCEPTION HERE!!!* > } catch (RuntimeException e) { > e.printStackTrace(); > throw new ValidationException(message); > } > } > > @Override > public void render(Field field, String message, MarkupWriter writer, > FormSupport formSupport) { > > } > } > > Unfortunately it seems that my service is not properly injected by @Inject > and I get a NPE when I tried to use my service variable. > > Note that this does not occur with a ValueEncoder implementation that I use > elsewhere in the application... > > Can anyone help please? > > Regards, > > Julien. >