MVC 1.0
Manfred Riem (@mnriem)Oracle
Geertjan Wielenga (@geertjanw)Oracle
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
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.
M
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Agenda
MVC
MVC 1.0 JSR
Some examples
MVC tooling
Questions and Answers
1
2
3
4
5
E
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
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
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
The M(odel) 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
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
The V(iew) 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.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
The C(ontroller) in MVC• The controller is the work horse of the pattern, as it:– Executes the business logic• Run a credit card transaction
– Updates the model• Mark the transaction as successful in the model object
– Ask the view to render itself• Shows the transaction was successful
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Different styles of MVC• Component-based MVC• Action-based MVC• Other styles
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
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)
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Action-based MVC• Controller(s) defined by the application• Currently no JavaEE implementation– Good news we are creating one!
• Some examples– Struts 1 (end of life)– Struts 2– Spring MVC
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
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 libraries that implement
re-usable behavior– Components render HTML / JavaScript– Automatic input conversion– Automatic input validation– Page centric
Compare and contrast
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Agenda
MVC
MVC 1.0 JSR
Some examples
MVC tooling
Questions and Answers
1
2
3
4
5
E
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
The MVC 1.0 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?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
List of supporters
• 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
(see JCP page)
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Where and how?• Where are we at?– The JSR has been approved–We have the EG up and running
• How can I help?– Join the [email protected] mailinglist and comment– Participate in the Adopt-a-JSR program (JUGs)– Test out snapshots (once available) from the RI website
(http://ozark.java.net) and file issues if something is not working– Tweet, blog, socialize to raise awareness about MVC 1.0
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
An example about the EG process• We are currently in the middle of a discussion about the following
question: “Do we build on top of JAX-RS or not?”• Since the [email protected] mailing list gets every mail the EG sends
you can follow this discussion as well• What do you think?– Tell us on the mailing list– Tweet about it– Talk to me after the session
• Why do I ask?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Another couple of things being discussed• Programmatic API so you can change the runtime behavior • Type conversion of form inputs• An SPI to plug in a different view technology– Velocity– Freemarker– Thymeleaf–… Your view technology …
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Agenda
MVC
MVC 1.0 JSR
Some examples
MVC tooling
Questions and Answers
1
2
3
4
5
E
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
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.
M
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
A rough JSP example• Initial JSP page• CDI Managed Bean (also known as the the controller)• Result JSP page
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Initial JSP page<!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>
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
CDI Managed Bean (the controller)• @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 …}
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Result JSP page<!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>
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
A rough Facelet example• Initial Facelet page• CDI Managed Bean (also known as the controller)• Result Facelet page
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Initial Facelet page<!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>
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
CDI Managed Bean (aka the controller)• @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 …}
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Result Facelet Page<!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>
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Another Facelets example• Template page• Initial Facelet page• CDI Managed Bean (also known as the controller)• Result Facelet page
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Template Page<html> <h:head> <!– Put your CSS / JavaScript here --> </h:head> <h:body> <div id="content" class=”content”> <ui:insert name="content">Main Content</ui:insert> </div> </h:body></html>
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Initial Page (using template)<html> <h:body> <ui:composition template=”template.xhtml”> <ui:define name="content”> <form action=”/rough-example/form1a.xhtml”> <input id="input1" jsf:value="#{roughExampleBean.value}"/> <input id="submit" type="submit" value="Submit"/> </form> </ui:define> </ui:composition> </h:body></html>
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
CDI Managed Bean (aka the controller)• @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 …}
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Result page (using template)<html> <h:body> <ui:composition template=”template.xhtml”> <ui:define name="content”> We did a POST to an action based URL and the result is:
#{roughExampleBean.value} </ui:define> </ui:composition> </h:body></html>
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Some brief examples@GET @Path(“mypath”)public String mypath(@Inject @HeaderParam(“myheader”) String header)
@POST @Path(“mypath2”)public String otherName(@Inject HttpSession session)
@PUT @Path(“mypath3/{mypath}”)public String myName(@Inject @PathParam mypath)
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Some brief examples (continued)@GET @Path(“spec_lead”)@RolesAllowed(“spec_lead”)public String specLead()
@GET @Path(“eg_member”)@RolesAllowed(“eg_member”)@ServerPush({“my.css”, “my.js”})public String egMember()
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Recap• Doing MVC now is not a bad idea, because we can:– Leverage CDI– Leverage Servlet 4.0 (ServerPush)– Leverage Facelets– Deliver an easy migration path if you are using JSPs
• Can you get involved? Yes, how:– Join our users mailing list– Tweet about MVC– Blog about MVC– Test out SNAPSHOT and milestone builds from https://ozark.java.net (once available)
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Agenda
MVC
MVC 1.0 JSR
Some examples
MVC tooling
Questions and Answers
1
2
3
4
5
E
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
MVC ToolingWhile it is not really part of the specification cycle perse we think to have tooling that allows you to work with MVC 1.0 is integral to a good developer experience
So I have invited Geertjan to be my co-speaker to cover ideas he has with respect to tooling and he will take it from here
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Links• MVC specification – Website http://mvc-spec.java.net– Users Mailing List [email protected]
• MVC implementation – Website http://ozark.java.net– Users Mailing List [email protected]
• Spec leads– Santiago (@spericas)– Manfred (@mnriem, https://www.java.net/blogs/mriem)
• Tooling– Geertjan (@GeertjanW, https://blogs.oracle.com/geertjan)
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Questions?• Ask them now• Talk to us afterwards