2015 javaone lad jsf 2.3 & mvc 1.0

38

Upload: mnriem

Post on 07-Aug-2015

178 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: 2015 JavaOne LAD JSF 2.3 & MVC 1.0
Page 2: 2015 JavaOne LAD JSF 2.3 & MVC 1.0
Page 3: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

Pick  Your  Java  EE  Front  End  JavaServer  Faces  or  Model-­‐View-­‐Controller  

Manfred  Riem  Principal  Member  of  Staff  @mnriem  

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

Page 4: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Safe  Harbor  Statement  The  following  is  intended  to  outline  our  general  product  direcQon.  It  is  intended  for  informaQon  purposes  only,  and  may  not  be  incorporated  into  any  contract.  It  is  not  a  commitment  to  deliver  any  material,  code,  or  funcQonality,  and  should  not  be  relied  upon  in  making  purchasing  decisions.  The  development,  release,  and  Qming  of  any  features  or  funcQonality  described  for  Oracle’s  products  remains  at  the  sole  discreQon  of  Oracle.  

4  

Page 5: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Program  Agenda  

What  is  currently  available?  

JSF  2.3  

MVC  1.0  

How  to  contribute  

Closing  remarks  

1  

2  

3  

4  

5  

5  

Page 6: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Program  Agenda  

What  is  currently  available?  

JSF  2.3  

MVC  1.0  

How  to  contribute  

Closing  remarks  

1  

2  

3  

4  

5  

6  

Page 7: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

What  is  currently  available?  

• Glassfish  4.1  – Reference  implementaQon  of  JavaEE  7,  which  includes  JSF  2.2.  

• WLS  12.2.1  – Coming  soon  

• Other  vendors  – Some  have  already  released  – Some  have  announced  when  they  are  going  to  be  available  

7  

Page 8: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

What  is  currently  available  (cont.)  ?  

•  JSF  2.2  – Resource  library  contracts  – Stateless  views  – CSRF  protecQon  – File  upload  – Faces  flows  

8  

Page 9: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

<f:view  contracts=“#{contractBean.contract}”>        <ui:composition  template=“/template.xhtml”>            <ui:define  name=“content”>              main  content          </ui:define>            <ui:define  name=“footer”>              footer  info          </ui:define>        </ui:composition>    </f:view>  

JSF  2.2  Resource  library  contracts  (using  HTML  page)  

Page 10: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

@SessionScoped  @Named(“contractBean”}  Public  class  ContractBean  {          private  String  contract          public  String  getContract()  {            this.contract  =  contract;        }  }  

JSF  2.2  Resource  library  contracts  (Java  code)  

Page 11: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

JSF  2.2  Resource  library  contracts  (filesystem  layout)  

•  contracts  – layout1  •  css  –  layout.css  

•  header.xhtml  

– layout2  •  template.xhtml  

11  

Page 12: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

<f:view  transient=“true”>        <ui:composition  template=“/template.xhtml”>            <ui:define  name=“content”>              main  content          </ui:define>            <ui:define  name=“footer”>              footer  info          </ui:define>        </ui:composition>    </f:view>  

JSF  2.2  Stateless  Views  

Page 13: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

JSF  2.2  Stateless  Views  (cont.)  

• A  view  is  considered  stateless  if  the  transient  adribute  is  set  to  true,  however:  – Stateless  means  that  NO  view  state  will  be  kept  – CDI  /  JSF  managed  beans  can  sQll  exist  – View  scoped  beans  acts  like  Request  scoped  beans  

13  

Page 14: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

JSF  2.2  Faces  Flows  

• A  flow  is  a  collecQon  of  resources  that  represent  a  specific  flow  of  pages,  it  can  contain  or  use:  – HTML  files  – CSS  files  – Java  Beans  – Resource  Library  contracts  

14  

Page 15: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

<f:view>        <h:form  enctype=“multipart/form-­‐data”>  

     <h:inputFile  value=“#{fileUploadBean.uploadedFile}”>    </h:inputFile>  

   <h:commandButton  value=“Submit”/>  

     </h:form>    </f:view>    

JSF  2.2  File  Upload  

Page 16: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

@RequestScoped  @Named(“fileUploadBean”}  Public  class  FileUploadBean  {              private  Part  uploadedFile;            public  Part  getUploadedFile()  {                  return  uploadedFile;          }            public  void  setUploadedFile(Part  uploadedFile)  {                  this.uploadedFile  =  uploadedFile;          }  }  

JSF  2.2  File  Upload  (Java  code)  

Page 17: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Program  Agenda  

What  is  currently  available?  

JSF  2.3  

MVC  1.0  

How  to  contribute  

QuesQons  and  Answers  

1  

2  

3  

4  

5  

17  

Page 18: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

What  is  on  the  table  for  JSF  2.3?  

•  Tie  up  the  loose  ends  – SpecificaQon  clarificaQons  – CDI  alignment  •  Ease  of  use  e.g.  @Inject  FacesContext  • @Inject  into  Validators,  Converters,  etc.  

– HtmlInputHidden  is  ClientBehaviorHolder  

•  Small  scale  new  features  

•  JSON  ajax  component  rendering  •  Stateless  enhancements  • GET  enhancements  • Adopt-­‐a-­‐JSR  

18  

Page 19: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

@FacesConverter(forClass  =  InjectConverterItem.class,  managed  =  true)  public  class  InjectConverter  implements  Converter  {            public  InjectConverter()  {          }            @Override          public  Object  getAsObject(FacesContext  context,  UIComponent  component,  String  value)                    {                  return  value;          }            @Override          public  String  getAsString(FacesContext  context,  UIComponent  component,  Object  value)            {                  return  value.toString();          }  }  

JSF  2.3  Converter  injecQon  (CDI  managed  converter)  

Page 20: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

@FacesValidator(value  =  "injectValidator",  isDefault  =  false,  managed  =  true)  public  class  InjectValidator  implements  Validator  {            public  InjectValidator()  {          }            @Override          public  void  validate(FacesContext  context,  UIComponent  component,                            Object  value)  throws  ValidatorException  {          }  }    

JSF  2.3  Validator  injecQon  (CDI  managed  converter)  

Page 21: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

@Named(value  =  "injectSessionMapBean")  @ApplicationScoped  public  class  InjectSessionMap2Bean  implements  Serializable  {            @Inject          @SessionMap          private  Map<String,  Object>  sessionMap;            public  String  getValue()  {                  sessionMap.put("key",  "value");                  return  sessionMap.toString();          }  }    

JSF  2.3  Session  Map  injecQon  

Page 22: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

@Named(value="injectFacesContextBean")  @RequestScoped  public  class  InjectFacesContextBean  {            @Inject          FacesContext  context;            public  String  getValue()  {                  return  context.toString();          }  }    

JSF  2.3  Faces  Context  injecQon  

Page 23: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

JSF  2.3  Other  EG  contribuQons  

•  Support  for  more  data  types  on  ui:repeat  and  h:dataTable  • @FacesDataModel  allow  generic  types  •  Your  contribuQon?  

Some  done,  some  in  progress  

23  

Page 24: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Program  Agenda  

What  is  currently  available?  

JSF  2.3  

MVC  1.0  

How  to  contribute  

Closing  remarks  

1  

2  

3  

4  

5  

24  

Page 25: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Where  are  we  at?  •  The  first  Early  Dran  has  been  published  • Our  first  Milestone  release  is  available  • Our  road  map  is  aligning  with  the  JavaEE  8  roadmap  • We  are  requiring  JAX-­‐RS  as  we  build  on  top  of  it  • We  are  requiring  Java  8  • We  have  integrated  mulQple  contribuQons  from:  – our  EG  members    – external  contributors    

25  

Page 26: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

@Path("book")  public  class  BookController  {                    @Inject          private  Catalog  catalog;            @Inject          private  Models  models;            @GET          @Controller          @Produces("text/html")          @Path("view1/{id}")          public  String  view1(@PathParam("id")  String  id)  {                  models.put("book",  catalog.getBook(id));                  return  "book.xhtml";          }  }    

MVC  1.0  Controller  example  (Controller  code)  

Page 27: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

public  class  Book  {            private  String  title;            public  String  getTitle()  {                  return  title;          }            public  void  setTitle(String  title)  {                  this.title  =  title;          }  }  

MVC  1.0  Controller  example  (Book  class)  

Page 28: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

<html  xmlns:h=http://xmlns.jcp.org/jsf/html>  ...          <h1>Book  information</h1>      <p>#{book.title}</p>      ...  </html>        

MVC  1.0  Controller  example  (HTML  page)  

Page 29: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Standard  ViewEngines  •  JSP  •  Facelets  

29  

Page 30: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

ViewEngine  contribuQons,  supported  by  community  • AsciiDoc  •  Freemarker  • Handlebars  •  JSR  223  – Groovy  – Nashorn  

• Mustache  •  Thymeleaf  • Velocity  

30  

Page 31: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Enabling  ViewEngine  extensions  • Maven  users  include  the  extension  dependency  – E.g.  for  Velocity  •   <dependency>  

 <groupId>com.oracle.ozark.ext</groupId>    <arQfactId>ozark-­‐velocity</arQfactId>    <version>x.y.z</version>    <scope>compile</scope>  </dependency>  

• Use  the  correct  extension  for  the  enabled  view  engine  – E.g.  for  Velocity  •  Velocity  have  a  .vm  extension  

• Non-­‐maven  users  have  to  include  the  JARs  manually  

31  

Page 32: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Program  Agenda  

What  is  currently  available?  

JSF  2.3  

MVC  1.0  

How  to  contribute  

Closing  remarks  

1  

2  

3  

4  

5  

32  

Page 33: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

How  to  contribute  to  JSF  2.3  •  Join  the  users@jsf-­‐spec.java.net  mailing  list  and  comment  • ParQcipate  in  the  Adopt-­‐a-­‐JSR  program  (JUGs)  •   Test  out  milestones  /  snapshots  from  the  RI  website    (hdp://javaserverfaces.java.net)  and  file  issues  if  something  is  not  working  •  Tweet,  blog,  socialize  to  raise  awareness  about  JSF  2.3  • Contribute  substanQal  code  – Step  1  –  Write  the  code  – Step  2  –  Sign  the  OCA  (Oracle  Contributor  Agreement)  – Step  3  –  See  your  contribuQon  be  accepted  and  see  a  tweet  announcing  it!  

33  

Page 34: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

How  to  contribute  to  MVC  1.0  •  Join  the  users@mvc-­‐spec.java.net  mailing  list  and  comment  • ParQcipate  in  the  Adopt-­‐a-­‐JSR  program  (JUGs)  •   Test  out  milestones  /  snapshots  from  the  RI  website    (hdp://ozark.java.net)  and  file  issues  if  something  is  not  working  •  Tweet,  blog,  socialize  to  raise  awareness  about  MVC  1.0  • Contribute  substanQal  code  – Step  1  –  Write  the  code  – Step  2  –  Sign  the  OCA  (Oracle  Contributor  Agreement)  – Step  3  –  See  your  contribuQon  be  accepted  and  see  a  tweet  announcing  it!  

34  

Page 35: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Program  Agenda  

What  is  currently  available?  

JSF  2.3  

MVC  1.0  

How  to  contribute  

Closing  remarks  

1  

2  

3  

4  

5  

35  

Page 36: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Closing  remarks  • Picking  JSF  or  MVC  is  a  mader  of  choice,  but  please  consider  this  – JSF    •  Availability  of  JSF  component  frameworks  which  allow  you:  –   to  deliver  a  consistent  UI  across  department  –   foster  re-­‐use  of  components  

•  Complexity  of  rendering  is  hidden  from  the  user  

– MVC    •  Standardize  an  acQon/controller  based  approach  •  Stays  out  of  your  way  with  respect  to  rendering    •  Lots  of  ViewEngines  available,  new  ones  easy  to  integrate  

•  JSF  and  MVC  are  complementary  to  each  other  and  they  can  co-­‐exist!  

36  

Page 37: 2015 JavaOne LAD JSF 2.3 & MVC 1.0

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

Safe  Harbor  Statement  The  preceding  is  intended  to  outline  our  general  product  direcQon.  It  is  intended  for  informaQon  purposes  only,  and  may  not  be  incorporated  into  any  contract.  It  is  not  a  commitment  to  deliver  any  material,  code,  or  funcQonality,  and  should  not  be  relied  upon  in  making  purchasing  decisions.  The  development,  release,  and  Qming  of  any  features  or  funcQonality  described  for  Oracle’s  products  remains  at  the  sole  discreQon  of  Oracle.  

37  

Page 38: 2015 JavaOne LAD JSF 2.3 & MVC 1.0