|
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.
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>
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.
<component-lib:button/>
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.)
Copyright © 2024 Andrew Oliver