Services

Our component library provides some extended services to help easing developement. From our experience, these features really help completing Tapestry 5 base services on diverses themes.

Security : Authorize

Exanpe-t5-lib provides a full set of services to apply some fine-grained role based security in your application.
With the annotation @Authorize and the component Authorize, you can apply security on :
  • The whole page, setting the @Authorize annotation on your page class.
  • A method, setting the @Authorize annotation on your page class method.
  • A chunk of rendering, using the
    <t:authorize>
    component
    .
  • Anything, using the Authorize mixin.

Everything is base on the roles declared in the current user java.security.Principal, no matter how nor with which framework you initialize them.
All 4 authorization level are based on a unique way for defining the authorized roles :
  • any : Any role required to grant access
  • all : All role required to grant access
  • not : Any role deny access

Session Management : ContextPageReset

Presentation

Session management can be a pain, in any application. Tapestry 5 provides @Persist and @SessionAttribute to store, @PageReset and @DiscardAfter to clean, but that was not enough for our applications.

We needed a way to clean up a page's information on specific case, which has to "reboot" the page, and moreover, a whole "navigation context".
This is the goal of the @ContextPageReset annotation.

Any method annotated with @ContextPageReset will be triggered upon a specific context value present in the URL.
Note that this feature have to be activated (it is deactivated by default to avoid regression as the context value becomes unusable)


The context

By default, the context triggering the method call is "reset", meaning that everytime you call an URL with /reset inside, the clean up will be done.
This means that you will no longer be able to call a URL containing "/reset".
This value can be modified by contributing a Symbol in your Module class :
    public static void contributeApplicationDefaults(MappedConfiguration<String, String> configuration)
    {
        ...
        configuration.add(ExanpeSymbols.CONTEXT_PAGE_RESET_MARKER, "new_context");
        ...
    }
      
      

Feature activation

To activate the feature, you have to explicitly add in your Module class :
    
    public void contributeComponentRequestHandler(OrderedConfiguration<ComponentRequestFilter> configuration)
    {
        ...
        configuration.addInstance("ContextPageResetFilter", ContextPageResetFilter.class);
        ...
    }
    
    
Also, as the whole Tapestry page transformation have been modified in Tapestry 5.3, a package protected method "void onActivate()" have to be present in any Tapestry 5.3 page's class containing a @ContextPageReset. Please have a look at the demo for a concrete usage.

Internationalization : LocaleSession

Presentation

This feature allow you to store a language (through Locale) choosen by the user in the user session.
This differ from the default implementation storing the locale directly in the page links.
In order to speed up filter processing, this feature is not activated by default, as it is a very specific feature.

Store the locale

To store the locale depending on the user choice, you have to inject in your page the LocaleSessionService service, then set it.
      

Page :        
    @Inject
    private LocaleSessionService localeSessionService;

    void onActionFromFr()
    {
        localeSessionService.setLocale(Locale.FRANCE);
    }
}

Module : 
public static void contributeApplicationDefaults(MappedConfiguration<String, String> configuration)
    {
        ...
        configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en,fr");
        ...
    }

    

Feature activation

To activate the feature, you have to explicitly add in your Module class :
    
    public void contributeComponentRequestHandler(OrderedConfiguration<ComponentRequestFilter> configuration)
    {
        ...
        configuration.addInstance("LocaleSessionFilter", LocaleSessionRequestFilter.class);
        ...
    }