Quickstart
How to start using Medusa in your code
Last updated
How to start using Medusa in your code
Last updated
Add the medusa-ui
dependency, and make sure you have spring-boot-starter-webflux
included in your pom.xml
Under/src/main/resources
, create a folder called pages
Under this folder, add a hello-world.html
Comfortable with Spring Controllers? This will feel very familiar.
Create a classHelloWorldEventHandler
in an appropriate package (for example com.sample.medusa.eventhandler
).
Annotate it with@UIEventPage
and point it to the right page and path.
If you will be using variables within your page, you'll want to define an initial value for them. This value can be different per request. You do this by adding a setupAttributes method.
This step is often wanted, but not required. It is possible to simply create an @UIEventPage
that can only execute actions.
You can visualize the variable in your HTML page as a label within text, or as part of an attribute.
Labels are represented as such: <m:text item="name-of-the-variable" />
As an example, this is what your hello-world.html could look like. Notice you can also use it in something like the page title.
Interactivity is handled through so-called medusa expressions and attributes. They're nothing more than extensions to HTML.
For now, let's add a very simple example: A text label showing a number and a button. You press the button, the number in the text label increases.
We already saw how to add variables within HTML in the previous section.
Additionally, there are attributes available that can be added to HTML elements. One of those is m-click
So we change our hello-world.html
to something like this:
Now we should make the Java code aware of themy-counter
variable and theincrease
method.
The action you can do, increase()
, just becomes a method in your UIEventController
. This method returns DOMChanges
. We just add key/value pairs that need any changes on the level of the DOM.
That's it! Run the application and you'll see that you have direct integration with your backend.
After this, you should already be able to compile, run your application and be able to visit .
Browse the entire list of possible expressions .