19
“THE COST OF LEARNING” advantage of mixer2.org @nabedge DBFlute Fes at Shibuya, Tokyo 2015-11-21 http://connpass.com/event/21885/

The cost of learning - advantage of mixer2

Embed Size (px)

Citation preview

Page 1: The cost of learning - advantage of mixer2

“THE COST OF LEARNING”advantage of mixer2.org

@nabedge

DBFlute Fes at Shibuya, Tokyo

2015-11-21

http://connpass.com/event/21885/

Page 2: The cost of learning - advantage of mixer2

Who?

● Yu Watanabe● Java Engineer● Bizreach.inc● Project Mixer2

http://mixer2.org

2

Page 3: The cost of learning - advantage of mixer2

What is mixer2 ?

3

Template = 100% pure HTML & CSS

View = Plain Java

Hello <span id=”name”>foo bar</span>

Span span = html.getById(“name”, Span.class);span.replaceInner(“World !”);// You get // Hello <span id=”name”>World !</span>

Page 4: The cost of learning - advantage of mixer2

The cost of learning

4

Page 5: The cost of learning - advantage of mixer2

5

Productivity

▷ Type safe▷ Automatic

code generation

▷ Testability

▷ Convention over Configuration

▷ Framework

▷ The cost of learning

Page 6: The cost of learning - advantage of mixer2

Learning Curve

6

Page 7: The cost of learning - advantage of mixer2

How to reducecost to learn ?

7

Page 8: The cost of learning - advantage of mixer2

8

★ No learn★ Use that you

already know

Page 9: The cost of learning - advantage of mixer2

9

What do you know ?

▷ Java▷ HTML/CSS▷ Eclipse or IntelliJ▷ JSP + Custum tag▷ VTL (Velocity Template Language)▷ FTL (Freemarker Template

Language)▷ Thymeleaf property + OGNL

Page 10: The cost of learning - advantage of mixer2

Thymeleaf attributes and utility objects

#ctx

#vars

#locale

#dates

#calendars

#numbers

#strings

#bools

#arrays

#lists10

#sets

#maps

#aggregates

#messages

#ids

th:if

th:unless

th:text

th:class

th:attr

th:include

th:replace

th:each

th:switch

th:remove

Page 11: The cost of learning - advantage of mixer2

customization

11

1.1. Scenario 1: adding features to the Standard dialectsSay 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

Page 12: The cost of learning - advantage of mixer2

Scinario1

12

admin non-adminMonday to Saturday

blue red

Sunday green green

<input type=”text” class=”COLOR” />

Page 13: The cost of learning - advantage of mixer2

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();}

Page 14: The cost of learning - advantage of mixer2

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 supporter7 .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

Page 15: The cost of learning - advantage of mixer2

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

Page 16: The cost of learning - advantage of mixer2

What is your GOAL ?

16

A. Learn technologyB. Write codeC. Launch product

Page 17: The cost of learning - advantage of mixer2

““Done is better

than perfect .”

17

Page 18: The cost of learning - advantage of mixer2

Done with ease by Mixer2

18

Page 19: The cost of learning - advantage of mixer2

Thanks !

19