Annotation Type CheckedTemplate


  • @Documented
    @Retention(RUNTIME)
    @Target(TYPE)
    public @interface CheckedTemplate
    If you place this annotation on a class, all its native static methods will be used to declare templates and the list of parameters they require.

    The name of a method and the base path are used to locate the template contents. By default, the base path is derived from the annotation target:

    • If this is placed on a static nested class of an enclosing class with a simple name X, a native static method of the name foo will refer to a template at the path X/foo (template file extensions are not part of the method name) relative to the templates root.
    • If this is placed on a top-level class, a native static method of the name foo will refer to a template at the path foo (template file extensions are not part of the method name) at the toplevel of the templates root.
    The base path can be also specified via basePath().

    Each parameter of the native static will be used to validate the template at build time, to make sure that those parameters are used properly in a type-safe manner. The return type of each native static method should be TemplateInstance.

    Example:

     @Path("item")
     public class ItemResource {
    
         @CheckedTemplate
         static class Templates {
             // defines a template at ItemResource/item, taking an Item parameter named item
             static native TemplateInstance item(Item item);
         }
    
         @GET
         @Path("{id}")
         @Produces(MediaType.TEXT_HTML)
         public TemplateInstance get(@PathParam("id") Integer id) {
             // instantiate that template and pass it the required template parameter
             return Templates.item(service.findItem(id));
         }
     }
     
    • Field Summary

      Fields 
      Modifier and Type Fields Description
      static String DEFAULTED
      Constant value for basePath() indicating that the default strategy should be used.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      String basePath
      Example:
      boolean requireTypeSafeExpressions
      If set to true then the defined templates can only contain type-safe expressions.
    • Field Detail

      • DEFAULTED

        static final String DEFAULTED
        Constant value for basePath() indicating that the default strategy should be used.
    • Element Detail

      • basePath

        String basePath
        Example:
         @Path("item")
         public class ItemResource {
        
             @CheckedTemplate(basePath = "items_v1")
             static class Templates {
                 // defines a template at items_v1/item
                 static native TemplateInstance item(Item item);
        
                 // defines a template at items_v1/allItems
                 static native TemplateInstance allItems(List<Item> items);
             }
         }
         
        Returns:
        the base path relative to the templates root
        Default:
        "<<defaulted>>"
      • requireTypeSafeExpressions

        boolean requireTypeSafeExpressions
        If set to true then the defined templates can only contain type-safe expressions.
        Default:
        true