Top Banner
MVC 1.0 May 2015 David Delabassee @delabassee Oracle Copyright © 2014, Oracle and/or its affiliates. All rights reserved. 1
39

MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Dec 31, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

MVC  1.0May  2015

David  Delabassee  @delabassee  Oracle

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.  

1

Page 2: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

The  following  is  intended  to  outline  our  g  eneral  product  direction.  It  is  intended  for                        i  nformation  purposes  only,  and  may  not  be  incorporated  into  any  contract.  It  is  not  a  commitment  to  deliver  any  material,  code,  or  functionality,  and  should  not  be  relied  upon  in  making  purchasing  decisions.  The  development,  release,  and  timing  of  any  features  or  functionality  described  for  Oracle’s  products  remains  at  the  sole  discretion  of  Oracle.

Safe  Harbor  Statement

2

Page 3: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Lorem  ipsum  dolor  sit  amet,  MVC,  consectetur  adipiscing  elit,  sed  do  eiusmod  tempor  incididunt  ut  labore  et  dolore  magna  aliqua,  Action-­‐Based  MVC.  Ut  enim  ad  minim  veniam,  quis  nostrud  exercitation  ullamco  laboris  nisi  ut  aliquip  ex  ea  commodo  consequat.  JSR  371  duis  aute  irure  dolor  in  reprehenderit  in  voluptate  velit  esse  cillum  dolore  eu  fugiat  nulla  pariatur.  Ozark  excepteur  sint  occaecat  cupidatat  non  proident.

Personal  Statement

3

Page 4: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Agenda

Context  

MVC  1.0  JSR  

Conclusion

1

2

3

4

Page 5: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Agenda

Context  

MVC  1.0  JSR  

Conclusion

1

2

3

5

Page 6: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Java  EE  7

ENTERPRISE EDITION

• Batch • Concurrency • Simplified JMS

• More annotated POJOs • Less boilerplate code • Cohesive integrated platform

DEVELOPER PRODUCTIVITY

• WebSockets • JSON • Servlet 3.1 NIO • REST

MEETING ENTERPRISE

DEMANDS

Java EE 7

6

Page 7: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Java  EE  8

Clou

d

Mobile

HTTP/2

SECURITYReactive  Programming

User  Experience

7

Page 8: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Java  EE  8  Community  Survey

Should  Java  EE  provide  support  for  MVC  alongside  JSF?    

Is  there  any  one  de-­‐facto  standard  technology  in  this  space  to  which  we  should  look  for  inspiration?

8

Page 9: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved. 9

Page 10: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Community-­‐Prioritized  Features

10

http://glassfish.org/survey

Page 11: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

MVC

11

Controller

Model View

Request

Update

Get

Update

Page 12: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Component-­‐based  MVC• Specific  style  of  MVC  made  popular  by  component  frameworks  

– JavaServer  Faces  –Wicket    – Tapestry  – Seam  (discontinued),  Apache  Click  (retired)  

• Controller  provided  by  the  framework

12

Controller

Model View

Request

Update

Get

Update

Page 13: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Action-­‐based  MVC• Controller(s)  defined  by  the  application  

– Struts  1  (EoL),  Struts  2  – Spring  MVC  

• No  standard  Java  EE  implementation  – Good  news  we  are  creating  one!  – Targeted  for  inclusion  in  Java  EE  8

1313

Controller

Model View

Request

Update

Get

Update

Page 14: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Action-­‐based  MVC  

–Manual  request  parameter  processing  – No  view  kept  around  – Request  centric  – Developer  responsible  for  all  HTML  /  JS  – Limited  support  for  re-­‐usable  behavior  – No  automatic  input  conversion  – No  automatic  input  validation  

Component-­‐based  MVC  

– Automatic  request  parameter  processing  – View  kept  around  – Page  centric    – Components  handle  HTML  /  JS  – Component  implement  re-­‐usable  behavior  – Automatic  input  conversion  – Automatic  input  validation  

Compare  and  contrast

14

Page 15: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Agenda

Context  

MVC  1.0  JSR  

Conclusion

1

2

3

15

Page 16: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Model-­‐View-­‐Controller  (MVC  1.0)  Specification

• “Action-­‐based”  MVC  1.0  JSR  • Why?  

– UI  landscape  is  not  one  size  fits  all    – Java  EE  8  Community  Survey  – Talking  to  our  customers,  etc.  

• EG  –Oracle,  RedHat,  innoQ,  IBM,  Caelum,  LifeRay,  and  6  individuals  members  

• You  can  contribute  too!

JSR  371

16

                   Early  Draft  Review

Page 17: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Model-­‐View-­‐Controller  (MVC  1.0)  Specification

• Ozark  – https://ozark.java.net  

• Open  Source  – git://java.net/ozark~sources  – https://github.com/spericas/ozark

Reference  Implementation

17

Page 18: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.  

MVC  1.0

• Glues  together  key  Java  EE  technologies  –Model  :  CDI,  Bean  Validation,  JPA  –  View  :  Facelets,  JSP,  more?  –  Controller  :  Invent  new  technology  Vs.  Leverage  existing  technologies

18

Action-­‐based  MVC

Page 19: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Controller• Combine  data  models  and  views  to  produce  web  application  pages

@Path("hello") public class HelloController {

@GET@Controllerpublic String hello() {

return "hello.xhtml";}

}

19

Page 20: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Controller• Class/method  decorated  with  @Controller

@Path(“hello") @Controller public class HelloController {

@GET@View(“hello.ftl")public void hello() { }

}

20

Page 21: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Controller

@Path(“hello") @Controller public class HelloController {

@GETpublic Viewable hello() {

return new Viewable("hello.jsp"); } }

21

Page 22: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Controller

… @GET @Controller public Response getById(@PathParam("id") String id) { if (id.length() == 0) { return Response.status(Response.Status.BAD_REQUEST) .entity(“error.xhtml") .build(); } }

22

Page 23: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Model• “Refers  to  the  data”  • javax.mvc.Models  interface  • CDI  @Named  bean  (recommended)

23

Page 24: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Model @Named(“greeting”) @RequestScoped public class Greeting {

private String message;

public String getMessage() { return message;

} public void setMessage(String message) { this.message = message; } }

24

Page 25: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Model

@Path(“hello”) public class HelloController {

@Inject private Models models;

@GET @Controller public String hello() { models.put(“greeting”, new Greeting(“Hi JPrime”)); return “hello.ftl”; } }

25

Page 26: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

View• Define  the  structure  of  the  output  • Can  refer  to  model(s)  • Rendered  by  a  View  Engine  

– JSP  – Facelets  

• Not  accessible  as  static  resources  – /WEB-­‐INF/views/  

26

Page 27: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

View

27

<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC …> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"> <h:head> <title>Facelet!</title> </h:head> <h:body> <p>${greeting.message} to all</p> </h:body> </html>

Page 28: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

View

<%@ page contentType=“text/html;charset=UTF-8” language=“java” %> <html> <head> <title>Hello</title> </head> <body> <p>${greeting.message}</p> </body> </html>

28

Page 29: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

View  Engine• CDI  based  extension  mechanism  • javax.mvc.engine.ViewEngine interface  

boolean supports(String view);

void processView(ViewEngineContext context)

throws ViewEngineException;

• Ozark  – JSP  &  Facelets  – FreeMarker,  Velocity,  Thymeleaf,  Mustache  &  Handlebars

29

Page 30: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Demos?

30

Lorem  ipsum  dolor  sit  amet,  Intial  consectetur  adipiscing  elit,  sed  do  eiusmod  tempor  incididunt  ut  labore  et  dolore  magna  aliqua,  Ozark  Ut  enim  ad  minim  veniam,  quis  nostrud  exercitation  ullamco  laboris  nisi  ut  aliquip  ex  ea  commodo  consequat.  Velit  duis  aute  irure  dolor  in  reprehenderit  in  voluptate  velit  esse  cillum  dolore  eu  fugiat  nulla  pariatur.  milestone  build  excepteur  sint  occaecat  cupidatat  non  proident.

Page 31: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Miscellaneous• Bootstrap  

– javax.ws.rs.core.Application

• Validation  • Exception  Mapping  Providers  • @Produces  • CDI  Events  • Tooling

31

Page 32: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Agenda

Context  

MVC  1.0  JSR  

Conclusion

1

2

3

32

Page 33: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Conclusion• Doing  MVC  now  is  not  a  bad  idea,  because  we  are:  

– Leveraging  CDI,  JAX-­‐RS,  Facelets,  BV  –More?  Servlet  4.0’s  ServerPush  – Delivering  an  easy  migration  path  if  you  are  using  JSPs  

• Offers  more  choices  • New  annotations  

–@Controller  –@View

33

Page 34: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Java  EE  8

• Java  EE  8  Platform  (JSR  366)  • CDI  2.0  (JSR  365)  • JSON  Binding  1.0  (JSR  367)  • JMS  2.1  (JSR  368)    • Java  Servlet  4.0  (JSR  369)    • JAX-­‐RS  2.1  (JSR  370)  

• MVC  1.0  (JSR  371)  -­‐  EDR  • JSF  2.3  (JSR  372)  • Java  EE  Management  2.0  (JSR  373)  • JSON-­‐P  1.1  (JSR  374)  • Java  EE  Security  1.0  (JSR  375)

So  far…..

34

Page 35: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Roadmap• Q3  2014  Expert  Group  formed  • Q1  2015  Early  Draft  • Q3  2015  Public  Review  • Q1  2016  Proposed  Final  Draft  • Q3  2016  Final  Release  • TBC

35

Page 36: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Contribute!• Join  the  JCP    • “Adopt-­‐A-­‐JSR”  

– http://glassfish.java.net/adoptajsr  

• Get  involved  – Join  MVC  users  mailing  list  – Tweet,  blog,  socialize  to  raise  awareness  about  MVC  1.0  – Test  MVC  SNAPSHOT  and  milestone  builds  (https://ozark.java.net)  – Fill  issues!

36

Page 37: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Links• MVC  specification  

– http://mvc-­‐spec.java.net,  users@mvc-­‐spec.java.net  

• MVC  implementation    – http://ozark.java.net,  [email protected]  

• The  Aquarium  Blog  – https://blogs.oracle.com/theaquarium/

37

Page 38: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.

Mnogo  blagodaria!

38

Page 39: MVC - JPrime - Java Bulgarian User Group | BG-JUG · 2016. 12. 18. · Copyright©$2015, $Oracle$and/or$its$affiliates.$All$rights$reserved. 39. Title: MVC - JPrime Created Date:

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved. 39