Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Wiki Markup
{scrollbar}


Excerpt
hiddentrue

Adding a type coercion to enable the If component to test for anything

...

Code Block
languagejava
titleAppModule (partial, Tapestry 5.7.0+)
public static void contributeTypeCoercer(MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration) {

  add(configuration, SearchResult.class, Boolean.class,
      new Coercion<SearchResult, Boolean>() {
        public Boolean coerce(SearchResult input) {
          return !input.isEmpty();
        }
      });
}

private static <S, T> void add(MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration,
    Class<S> sourceType, Class<T> targetType, Coercion<S, T> coercion) {
  CoercionTuple<S, T> tuple = new CoercionTuple<S, T>(sourceType,
      targetType, coercion);

  configuration.add(tuple.getKey(), tuple);
}


Code Block
languagejava
titleAppModule.java (partial, pre-Tapestry 5.7.0)
public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) {

  add(configuration, SearchResult.class, Boolean.class,
      new Coercion<SearchResult, Boolean>() {
        public Boolean coerce(SearchResult input) {
          return !input.isEmpty();
        }
      });
}

private static <S, T> void add(Configuration<CoercionTuple> configuration,
    Class<S> sourceType, Class<T> targetType, Coercion<S, T> coercion) {
  CoercionTuple<S, T> tuple = new CoercionTuple<S, T>(sourceType,
      targetType, coercion);

  configuration.add(tuple);
}

...