Hints and Tips
This chapter provides some solutions for problems we’ve encountered ourselves or have been raised on the mailing lists/Slack channel.
Per-user Themes
From this thread on the Apache Causeway users mailing list:
-
Is it possible to have each of our resellers (using our Apache Causeway application) use their own theme/branding with their own logo and colors? Would this also be possible for the login page, possibly depending on the used host name?
Yes, you can do this, by installing a custom implementation of the Wicket Bootstrap’s ActiveThemeProvider
.
public class MyThemeProvider implements ActiveThemeProvider {
// ...
@Override
public ITheme getActiveTheme() { ... } (1)
@Override
public void setActiveTheme(final String themeName) { ... } (1)
}
1 | these methods won’t necessarily be called within a regular Causeway "interaction", so you may need to use the headless access pattern if - for example - persisting to Causeway-managed entities. |
To egister
@Override
protected void init() {
super.init();
final IBootstrapSettings settings = Bootstrap.getSettings();
settings.setThemeProvider(new BootswatchThemeProvider(BootswatchTheme.Flatly));
settings.setActiveThemeProvider(new MyThemeProvider(settings));
}
How i18n the Wicket viewer?
From this thread on the Apache Causeway users mailing list:
-
I am trying to internationalize the label descriptions of form actions, eg those in
ActionParametersFormPanel
. Referencing those via their message id inside a .po file didn’t work either. Can this be done?
Yes, it is possible to internationalize both the Wicket viewer’s labels as well as the regular translations of the domain object metadata using the .po
translation files as supported by the TranslationService.
Full details of the msgId
s that must be added to the translations.po
file can be found in i18n section of the beyond the basics guide.
Auto-refresh page
This requirement from the users mailing list:
-
"Suppose you want to build a monitoring application, eg for an electricity grid. Data is updated in the background (eg via the Restful Objects REST API). What is needed is the ability to show an entity that includes a map, and have it auto-refresh every 5 seconds or so."
Here’s one (somewhat crude, but workable) way to accomplish this.
-
First, update the domain object to return custom CSS:
public class MyDomainObject { ... public String cssClass() { return "my-special-auto-updating-entity"; } ... }
-
Then, use custom JavaScript to reload:
scripts/application.js$(function() { if ($(".my-special-auto-updating-entity").length) { setTimeout(function() {document.location.reload();}, 5000); // 1000 is 5 sec } });
SVG Support
(As per CAUSEWAY-1604), SVG images can be used:
-
as Logo in the upper left corner (Wicket Menubar)
-
on the Login Page (
login.html
) -
as favicon (
image/svg+xml
, cf. CAUSEWAY-1115)
However, SVGs are not, by default, displayed on the welcome page.
SVGs can be attached as Blob
s, but they are displayed as bitmaps (by means of the Batik rasterizer) and do not scale.
The rasterizer (of course) can not deal with animations (cf. attachment).
To fix this, you can add the following dependencies:
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-batik</artifactId> <!-- svg -->
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-batik</artifactId> <!-- svg -->
<version>3.3.2</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.8</version>
</dependency>
However, please note that these dependencies have high CVE values, and so may constitute a security risk.
Further discussion on this mailing list thread.