Excuse me, the contribute method in the previous email was not the one used
for coercion errors.

It should have looked like this


    public static void contributeValueEncoderSource(
            MappedConfiguration<Class<LibraryEvent>,
ValueEncoderFactory<LibraryEvent>> configuration) {
        configuration.addInstance(LibraryEvent.class, LibraryEncoder.class);
    }


and with this one I just implemented the method required for implementing
the ValueEncoderFactory on my encoder.




On Wed, Feb 20, 2013 at 3:49 PM, Chris Mylonas <ch...@mrvoip.com.au> wrote:

> Hi Tapestry List, long time no hear...
>
> How do you make tapestry spit out what encoder/coercions are supported.
> My encoder doesn't seem to be getting registered
>
> I am writing an app and have had to use a ValueEncoder.  I don't know
> where I am going wrong, I've written them before...and for the past 3 days
> get the same stupid coercion message.
>
> My understanding is
> 1.  Write encoder that implements ValueEncoder
> 2.  Contribute to value encoders
> 3.  encoder="myNewEncoder" in the tapestry component to use where no
> coercions come out-of-the-box
>
> I have tried two alternatives and would like to know where I've gone wrong
> in either please.
>
> 1.  Using Igor's Tapestry 5 book, I wrote a class called
> LibraryEventEncoder and placed it in an uncontrolled package, it implements
> ValueEncoder.
>
> package au.com.mrvoip.t5app.encoders ;
>
> public class LibraryEventEncoder implements ValueEncoder<LibraryEvent> {
>
>     private LibraryEventFacadeLocal _libraryEventService;
>
>     public LibraryEventEncoder(LibraryEventFacadeLocal libraryService) {
>         this._libraryEventService = libraryService;
>
>     }
>
>     @Override
>     public String toClient(LibraryEvent v) {
>         return String.valueOf(v.getId());
>     }
>
>     @Override
>     public LibraryEvent toValue(String id) {
>         return _libraryEventService.find(Long.valueOf(id));
>     }
> }
>
>
> AppModule receives this addition
>
>
>     @Contribute(ValueEncoderSource.class)
>     public static void provideEncoders(MappedConfiguration<Class,
> ValueEncoderFactory>configuration, final LibraryEventFacadeLocal lqmefl){
>         System.out.println("CHRIS THIS HAS BEEN CONTRIBUTED";
>         ValueEncoderFactory<LibraryEvent> factory = new
> ValueEncoderFactory<LibraryEvent>(){
>             public ValueEncoder<LibraryEvent> create(Class<LibraryEvent>
> clazz){
>                 return new LibraryEventEncoder(lqmefl);
>             }
>         };
>
>         configuration.add(LibraryEvent.class, factory);
>     }
>
>
> My page class uses a simple grid and the template follows
>
>     @EJB
>     private LibraryEventFacadeLocal libraryService;
>     @Property
>     private LibraryEvent lmevent;
>
>     @Property
>     private LibraryEventEncoder libeventEncoder = new
> LibraryEventEncoder();
>
>     public List<LibraryEvent> getLMEvents() {
>
>         return libraryService.getMostRecentDistinct("2720101"); //returns
> a short list (3-10 results usually)
>     }
>
>     public ValueEncoder<LibraryQueueMemberEvent> getLibEventEncoder(){
>         return libEventEncoder  ;
>     }
>
>
>
>     <t:grid source="lmevents" encoder="libEventEncoder" row="lmevent"
> rowsPerPage="50" >
>             <p:empty>
>               <p>There are no lmevents to display; you can add some
> manually when the link is made.</p>
>             </p:empty>
>         </t:grid>
>
>
>
>
> And the alternate way which appears to be popular - some private inner
> class as a replacement, as well as something like this directly in the get
> method.
>
>     public LibraryEventEncoder getLibEventEncoder() {
>         return new LibraryEventEncoder(lmService) {
>             public String toClient(LibraryEvent value) {
>                 return String.valueOf(value.getId());
>             }
>
>             public LibraryEvent toValue(String clientValue) {
>                 LibraryEvent e =
> libEventService.find(Long.valueOf(clientValue));
>                 if (String.valueOf(e.getId()).equals(clientValue)) {
>                     return e;
>                 }
>                 return null;
>             }
>         };
>     }
>
>
> But all the time I'm getting a problem with coercion of String to
> LibraryEvent even with the System.out.println message being spat out of
> logs that this encoder is being contributed (or at least i think it is)
>
>
> Any pointers would be helpful
> Chris
>
>


-- 

-- sent from web mail --

Reply via email to