This project demonstrates a custom webforJ component: SvgViewer.
SvgViewer is a reusable UI component for displaying and interacting with SVG images. It provides:
- Zoom in/out controls
- Drag-to-pan functionality
- Clickable SVG elements (with callback for element id)
- Customizable styling via CSS
SvgViewer svgViewer = new SvgViewer();
svgViewer.setContent(Assets.contentOf("/img/lifecycle-listeners.svg"));
svgViewer.onClick(id -> {
System.out.println("SVG element clicked: " + id);
});
parentLayout.add(svgViewer);- Zoom: Use the + and - buttons to zoom the SVG in and out. Zoom step and limits are configurable.
- Pan: Click and drag the SVG area to pan.
- SVG Element Click: Listen for clicks on SVG elements by id using
onClick. - Styling: All styles are in
svgviewer.cssand can be customized. - JS Integration: Drag-to-pan and SVG click detection are handled via
svgviewer.js.
- Place your SVG file in the static resources folder (e.g.,
src/main/resources/static/img/). - Add the component to your view as shown above.
- Optionally, register a click listener for SVG element ids.
- Java 21 or newer
- Maven 3.9+
To run the application in development mode:
mvn jetty:runThen open http://localhost:8080 in your browser.
This project is preconfigured to use the Jetty Maven Plugin, which makes development faster. It includes automatic scanning for class and resource changes.
By default, this project enables Jetty's scan mode using the following property:
<jetty.scan>1</jetty.scan>This means Jetty will poll for changes in compiled classes and resources every second, allowing the app to auto-reload without restarting the server. This is great for quick feedback while developing UI or backend logic.
If you're using a live reload tool (like JRebel or similar), you may want to set this to 0 to disable it.
<jetty.scan>0</jetty.scan>To run end-to-end and integration tests:
mvn verifyThis command:
- Starts Jetty before tests using the
jetty:startgoal - Runs integration tests using the Failsafe Plugin (tests ending with
*IT.java) - Shuts down Jetty after tests complete
To create a WAR file for deployment:
mvn clean package -PprodThe WAR file will be created in target/easirundemo-1.0-SNAPSHOT.war
Explore the webforJ ecosystem through our documentation and examples: