Date post: | 14-Dec-2015 |
Category: |
Documents |
Upload: | gideon-caywood |
View: | 221 times |
Download: | 3 times |
@mnriem#DV14 #MVC
MVC 1.0 in JavaEE 8
• A long time coming, or like some would say “finally!”• Why are we doing it now?
• Survey input
• Customer input
• JavaEE is about standards
• What are we looking at?
• Tight CDI integration
• Build on top of existing APIs
@mnriem#DV14 #MVC
MVC 1.0
• Some common questions• Can’t you do MVC with JAX-RS already?
• Indeed there is MVC support in Jersey and RESTeasy
• However it is not defined by a standard
• Will it replace JSF?
• Why do you ask?
• Can you do everything using one tool?
@mnriem#DV14 #MVC
How to control?
• A Servlet that:• Uses the CDI runtime to get a managed bean that
matches the annotated method for a given URI
• Invokes the method and gets back the response
• Forwards the request to the view language engine as determined by the response
• Integrates with the rest of the CDI runtime so it plays well with other CDI artifacts like interceptors
@mnriem#DV14 #MVC
How to model?
• As the controller already uses the CDI runtime, the model in your MVC application will be using the CDI to define its model
• Please understand that we are talking about the model for the view (not the models you would need to define for any other layer beyond your view layer)
@mnriem#DV14 #MVC
How to render?
• How to render the view• JSP
• Facelets
• Other view languages• Deliver a SPI so a vendor can hook in their own view
language
@mnriem#DV14 #MVC
2 rough examples
• A JSP based example• A Facelets based
example
@mnriem#DV14 #MVC
A rough JSP example
• Initial JSP page• CDI Managed Bean (also known as the the
controller)• Result JSP page
@mnriem#DV14 #MVC
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>
@mnriem#DV14 #MVC
CDI Managed Bean@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 …}
@mnriem#DV14 #MVC
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>
@mnriem#DV14 #MVC
A rough Facelet example
• Initial Facelet page• CDI Managed Bean (also known as the controller)• Result Facelet page
@mnriem#DV14 #MVC
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>
@mnriem#DV14 #MVC
CDI Managed Bean@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 …}
@mnriem#DV14 #MVC
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>
@mnriem#DV14 #MVC
MVC 1.0
• If you want to know more about MVC 1.0• Attend my session
• When: Friday
• What time: 10:45 - 11:45
• Where: Room 4
• Follow the discussion on the [email protected] mailing list
• Try out SNAPSHOTs from http://ozark.java.net/ (once available)
• Keep an eye on my twitter handle @mnriem