@mnriem#DV14 #MVC MVC 1.0 in JavaEE 8 A long time coming, or like some would say “finally!” Why...
-
Upload
gideon-caywood -
Category
Documents
-
view
220 -
download
3
Transcript of @mnriem#DV14 #MVC MVC 1.0 in JavaEE 8 A long time coming, or like some would say “finally!” Why...
![Page 1: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/1.jpg)
@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
![Page 2: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/2.jpg)
@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?
![Page 3: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/3.jpg)
@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
![Page 4: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/4.jpg)
@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)
![Page 5: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/5.jpg)
@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
![Page 6: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/6.jpg)
@mnriem#DV14 #MVC
2 rough examples
• A JSP based example• A Facelets based
example
![Page 7: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/7.jpg)
@mnriem#DV14 #MVC
A rough JSP example
• Initial JSP page• CDI Managed Bean (also known as the the
controller)• Result JSP page
![Page 8: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/8.jpg)
@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>
![Page 9: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/9.jpg)
@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 …}
![Page 10: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/10.jpg)
@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>
![Page 11: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/11.jpg)
@mnriem#DV14 #MVC
A rough Facelet example
• Initial Facelet page• CDI Managed Bean (also known as the controller)• Result Facelet page
![Page 12: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/12.jpg)
@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>
![Page 13: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/13.jpg)
@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 …}
![Page 14: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/14.jpg)
@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>
![Page 15: @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.](https://reader035.fdocuments.in/reader035/viewer/2022062407/56649c7d5503460f94932949/html5/thumbnails/15.jpg)
@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