Home / TeaVM Patterns and Pitfalls     frequal.com

Flavour: The Latest Web Framework

There's a new feature-rich web framework that includes: It's called Flavour. Let me show you what it can do.

Flavour Templates

Flavour is a powerful, modern web framework with great tooling. You code your pages in HTML with CSS for styling. To inject data into the pages, use <html:text>:
  Welcome back <html:text value="username">
Where does username come from? Flavour has a class bound to each HTML template, and it automatically invokes getters when there is a match. So in this case, it calls getUsername() in the bound class.

Pre-Made Components

Flavour makes heavy use of components. You can use the ones it provides and create your own. In the example above, you can see a Flavour pre-made component. html:text is a component that computes a value and inserts it into the page.

Other components allow for conditionals (std:if) and looping (std:foreach).

For interactivity, your page needs to be able to respond to events. event:click let's you specify which method gets called when an element is clicked:

  <button event:click="compute()">Compute<button>

Custom Components

You can define your own components, then use them in your pages or even to build other components.

A Flavour component is the combination of an HTML template with a class. Just like with page templates, methods mentioned on the page are invoked from the class bound to the template.

Say you have a custom button you want to use throughout the website, with consistent behavior when clicked. Simply create your CustomButtonComponent class, give it a name via the BindElement annotation, and bind it to customButton.html.

Then you can reuse the button in other HTML templates. First, include it at the top of the template:

  <?use component-lib:com.mycompany.components?>
Then insert the component using its prefix and name (from BindElement). Place it on the page and position it using normal HTML mechanisms.

Easy REST Calls

Invoking REST services can be a maintenance headache: Flavour eliminates most of these sources of error. Say you have a JAX-RS service with an interface Math, deployed at /mathapi. On the server side, you've already defined the paths and parameters in this interface. To invoke it, use Flavour to create a client-side implementation, and call the methods like you would any Java method:
  Math math = RESTClient.factory(Math.class).createResource("mathapi");
  int answer = math.add(2, 3);
Flavour handles all of the complexity -- marshaling and unmarshaling parameters, invoking the REST service, and error handling. (If things go wrong, an exception is thrown.)

Further Reading

Last modified on 25 Nov 2020 by AO

Copyright © 2020 Andrew Oliver