11. customization
11
1.1. Scenario 1: adding features to the Standard dialects
Say your application uses the SpringStandard dialect and that it needs to show an alert text
box in blue or red background depending on the user’s role (admin or non-admin) from
Monday to Saturday, but always in green on Sundays. You can compute this with conditional
expressions on your template, but too many conditions could render your code a little bit hard
to read…
Solution: create a new attribute called alertclass and an attribute processor for it (Java code
that will compute the right CSS class), and package it into your own MyOwnDialect dialect.
Add this dialect to your template engine with the th prefix (same as the SpringStandardone)
and you’ll now be able to use th:alertclass="${user.role}"!
http://www.thymeleaf.org/doc/tutorials/2.1/extendingthymeleaf.html
13. solution with thymeleaf
13
<input type=”text” th:alterclass=”${user.role}”
public interface IDialect {
public String getPrefix();
public Set<IProcessor> getProcessors();
public Map<String,Object> getExecutionAttributes();
public Set<IDocTypeTranslation> getDocTypeTranslations();
public Set<IDocTypeResolutionEntry> getDocTypeResolutionEntries();
}
14. lastaflute-mixer2 view class
14
1 public class SigninView extends OrleansBaseView {
2 private final ColorService colorService;
3 ...
4 protected void render(Html html, Mixer2Supporter supporter) {
5 Body body = html.getBody();
6 supporter
7 .findById(body, "account", Input.class)
8 .alwaysPresent(input -> {
9 input.setValue(form.account);
10 input.addCssClass(colorService.choice());
11 });
https://github.com/lastaflute/lastaflute-example-maihama/blob/master/maihama-
orleans/src/main/java/org/docksidestage/app/web/signin/SigninView.java
15. 15
To use Mixer2, You need
▷ Java
▷ HTML/CSS
▷ Eclipse or IntelliJ
▷ JSP + Custum tag
▷ VTL (Velocity Template Language)
▷ FTL (Freemarker Template
Language)
▷ Thymeleaf property + OGNL
16. What is your GOAL ?
16
A. Learn technology
B. Write code
C. Launch product