Hello Jonathan

New Tapestry user here, started with a bootstrapped 5.7.3 and experimenting.
>

Welcome + enjoy!


> What am I doing wrong?  There is really no room for error, the Blah class
> is defined right there in the same class and the current row object has
> absolutely no reason to be converted to String.
>

Quite the opposite - the String contained in the link needs to be coerced
back into a Blah object. Your code will render a useful link (e.g.,
http://localhost:8080/languages.delete/1). However, when the user clicks
it, Tapestry will have to coerce back the context ("1", in my example) to a
Blah object but doesn't know how, hence the error.

The solution is to contribute a Coercion<String, Blah>, defining how to
coerce from a String value to a Blah object. Add the following to your
AppModule:

     public static void
contributeTypeCoercer(MappedConfiguration<CoercionTuple.Key, CoercionTuple>
configuration) {
        Coercion<String, Blah> coercion = new Coercion<String, Blah>() {
            public Blah coerce(String input) {
               return new Blah(Integer.valueOf(input));
            }
        };
        CoercionTuple tuple = new CoercionTuple<String, Blah>(String.class,
Blah.class, coercion);
        configuration.add(tuple.getKey(), tuple);
    }

Note Blah cannot be a static class within the Languages page class. Put
Blah in its own package (not within pages, services, or components) and it
will work.

See https://tapestry.apache.org/type-coercion.html for more details on
coercion.

Cheers,

Volker

Reply via email to