+ All Categories
Home > Documents > MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014,...

MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014,...

Date post: 14-Jan-2016
Category:
Upload: elisha-maye
View: 216 times
Download: 0 times
Share this document with a friend
Popular Tags:
33
Transcript
Page 1: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Page 2: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Page 3: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

MVC in JavaEE 8

Manfred RiemPrincipal Member of Technical Staff

September, 2014

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

Page 4: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Safe Harbor StatementThe following is intended to outline our general product direction. It is intended for information 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.

Page 5: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Program Agenda

• MVC–What is MVC?– Different styles of MVC

• MVC 1.0 JSR– A rough JSP example– A rough Facelets example

Page 6: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

What is MVC?

• MVC is a pattern used to implement a user interface (UI).• It consists of 3 major components–Model (M) – View (V)– Controller (C)

• Each of the components has a distinct responsibility which is covered in the next slides

Page 7: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

The M in MVC

• The model is the interim state you want to keep when you are building an application that shows a user interface• Examples–Who is logged in–What are they trying to buy–What page are they on in a multi page flow

The Model

Page 8: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

The V in MVC

• The view is what your user interacts with – In a web application that would be the web page or web pages• your JSP page• your CSS styles• your JavaScript

– In a thick client scenario it would be the entire UI– In an embedded scenario it could be the touch screen, hardware buttons etc

The View

Page 9: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

The C in MVC

• The controller is the work horse of the pattern, as it:– Executes the business logic• Run a credit card transaction• Send out the order for fulfilling

– Updates the model• Mark the transaction as successful in the model object• Set the fulfillment date in the model object

– Ask the view to render itself• Shows the transaction was successful• Shows when to expect the order to be fulfilled

The Controller

Page 10: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Different styles of MVC

• Component-based MVC• Action-based MVC• Other styles

Page 11: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Component-based MVC

• A specific style of MVC made popular by component frameworks• Controller provided by the framework• Some examples– Java Server Faces (in the JavaEE platform)– Seam (discontinued)–Wicket – Tapestry– Apache Click (retired)

Page 12: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Page 13: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Action-based MVC

• Controller(s) defined by the application• Currently no JavaEE implementation– Good news there is one!

• Some examples– Struts 1 (end of life)– Struts 2– Spring MVC

Page 14: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Page 15: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Compare and contrast

• Action-based MVC–Manual request parameter processing– No view kept around– Limited support for re-usable behavior– Developer responsible for all HTML /

JavaScript– No automatic input conversion– No automatic input validation– Request centric

• Component-based MVC

– Automatic request parameter procession– View kept around (component tree)

– Component libraries that implement re-usable behavior– Components render HTML / JavaScript– Automatic input conversion– Automatic input validation– Page centric

High level overview

Page 16: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

The MVC JSR

Page 17: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

The MVC JSR

• It really is the “Action-based MVC 1.0” JSR• Where it this coming from?– JavaEE 8 survey– Talking to our customers– UI landscape is not one size fits all

• Who is supporting it?

Version 1.0

Page 18: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

The MVC JSR

• Joshua Wilson (Red Hat)• Woong-ki Lee (TmaxSoft)• Josh Juneau• Fabio Velloso (SouJava)• Yara Senger (SouJava)• Bruno Souza (SouJava)• Markus Karg

• Antonio Goncalves• Rajmahendra (JUGChennai)• Francisco Sokol• Werner Keil• Martijn Verburg (London Java

Community)• And of course Oracle

List of supporters (see JCP page)

Page 19: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

The MVC JSR

• Where are we at?– The JSR has just been approved–We are in the process of forming the EG

• How can I help?– Consider joining the EG– Participate in the Adopt-a-JSR program (JUGs)

• Where can I get more information?– See the end of the presentation– Talk / contact to the spec leads

Where, how and where?

Page 20: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Safe Harbor StatementThe following is intended to outline our general product direction. It is intended for information 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.

Page 21: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

The MVC JSR

• Initial HTML page• Managed Bean• Result HTML page

A rough JSP example

Page 22: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Rough JSP example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html> <head> <title>Rough example</title> </head> <body> <form action=”/rough-example/form1a.jsp”> <input id="input1" value="#{roughExampleBean.value}"/> <input id="submit" type="submit" value="Submit"/> </form> </body></html>

Initial HTML page

Page 23: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Rough JSP example

@Named("roughExampleBean”)@RequestScopedpublic class RoughExampleBean implements Serializable {

private String value;

@Path(value = "/form1a.jsp”) public String form1(@Inject HttpServletRequest request) { String input1 = request.getParameter("inputText1"); setValue("We set input1 manually to - " + input1); return "/form1b.jsp”; } … omitted getter/setter methods …}

Managed Bean

Page 24: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Rough JSP example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN” "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html> <head> <title>Rough example result page</title> </head> <body> We did a POST to an action based URL and the result is: #{roughExampleBean.value} </body></html>

Result HTML page

Page 25: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

The MVC JSR

• Initial HTML page• Managed Bean• Result HTML page

A rough Facelets example

Page 26: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Rough Facelets example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html> <head> <title>Rough example</title> </head> <body> <form action=”/rough-example/form1a.xhtml”> <input id="input1" jsf:value="#{roughExampleBean.value}"/> <input id="submit" type="submit" value="Submit"/> </form> </body></html>

Initial HTML page

Page 27: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Rough Facelets example

@Named("roughExampleBean”)@RequestScopedpublic class RoughExampleBean implements Serializable {

private String value;

@Path(value = "/form1a.xhtml”) public String form1(@Inject HttpServletRequest request) { String input1 = request.getParameter("inputText1"); setValue("We set input1 manually to - " + input1); return "/form1b.xhtml”; } … omitted getter/setter methods …}

Managed Bean

Page 28: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Rough Facelets example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN” "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html> <head> <title>Rough example result page</title> </head> <body> We did a POST to an action based URL and the result is: #{roughExampleBean.value} </body></html>

Result HTML page

Page 29: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Questions & Answers

Page 30: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Safe Harbor StatementThe preceding is intended to outline our general product direction. It is intended for information 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.

Page 31: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

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

Page 32: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Page 33: MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Recommended