KEMBAR78
Utilizing JSF Front Ends with Microservices | PDF
Utilizing JSF
Front Ends w Microservices
Code Smarter
Josh Juneau

Apress and Java Magazine Author

JCP Member, Apache NetBeans Contributor,

Java Champion, Jakarta EE Ambassadors
About Me
• Developer, DBA, System Administrator
• Author, Speaker, Podcaster
• Java Champion
• Apache NetBeans Developer
• Jakarta EE Ambassadors
Agenda
• Primer on newer features of Jakarta Server
Faces and Jakarta RESTful Web Services
• Simple services utilizing Jakarta EE
specifications.
• Basic Jakarta Server Faces front end to
display and update data via RESTful web
services.
• Incorporation of JSF frameworks to build
robust front ends.
How to Get Started
Today
• Download Eclipse GlassFish 5.1.0 (Utilize Payara
5.194+ for JDK 11 support)
• https://projects.eclipse.org/projects/
ee4j.glassfish
• Include Jakarta EE 8 dependencies into your
project
• Great examples:
• https://github.com/juneau001/JakartaEE-Playground
• https://projects.eclipse.org/projects/ee4j.jakartaee-platform/
Jakarta EE 8 Overview
• Continued enhancements for productivity
and web standards alignment
• Better alignment with Java SE 8
• Work towards a better platform for
development of microservices
Jakarta Server Faces
• Enhanced CDI
Alignment
• WebSocket
Integration
• Ajax Method
Invocation
• Class LevelValidation
• Java 8 Date-Time
• Iterable/Map/Custom
UIData Support
• Component Search
Expressions
• Radio Button
• styleclass on h:column
• Basic Support for
Extensionless URLs
New Features with 2.3
Utilize Date-Time API
Make use of the <f:convertDateTime /> tag.
New type attribute values on
<f:convertDateTime>:
• localDate, localTime, localDateTime
• offsetTime,offsetDateTime,
zonedDateTime
Jakarta Server Faces 3.0
• Removal of old cruft
• JSF’s own expression language
• Managed Beans
• Move more artifacts towards CDI
• Action Model (Not to compete with Krazo)
• Extensionless Mapping
Resource Injection
Inject JSF artifacts in JSF 2.3, and even
possible to inject into other JSF artifacts.
@Inject
private ExternalContext externalContext;
@Inject
private ServletContext servletContext;
How it Works
JSF 2.3 provides default producers for
many of the most commonly used JSF
artifacts, therefore, we can now inject
rather than hard-code.
Converters, validators and behaviors are
now also injection targets.
How it Works
Jakarta API for RESTful
Web Services
• Improved CDI Integration
• Reactive Client API
• Non-Blocking I/O
• https://github.com/jax-rs/spec
• Server Sent Events
• One way communication channel
• Text protocol,“text/event-stream” media
type
• Multiple messages
• Retry interval
Jakarta API for RESTful
Web Services
Building a Simple
Service
• JAX-RS
• JPA
• BeanValidation
Using JSF for Front End
• Model: Model Classes
• View: Facelets
• Controller: CDI Beans
• Wire together with Expression Language
Front End Service
• Utilize JAX-RS (RESTful Web Services) client
• All database work occurs within the
microservice (JPA, EJB if needed)
• Utilize JAX-RS to provide data to client
JAX-RS Client
Client client = ClientBuilder.newClient();
WebTarget resource = client.target(clientUri).path(clientService);
List<Roster> rosterList =
resource.request(javax.ws.rs.core.MediaType.APPLICATION_XML)
.get(new GenericType<List<Roster>>() {
})
RESTful Service
@GET
@Override
@Produces({MediaType.APPLICATION_XML,
MediaType.APPLICATION_JSON})
public List<Roster> findAll() {
return super.findAll();
}
Communicate (Demo)
• Basic communication to display database
table data
Writing or Modifying
Data
• Utilize @PUT and @POST
Writing or Modifying
Data
Writing or Modifying
Data
Writing or Modifying
Data
• Demo Utilizing JAX-RS forms and responses
Invoking Underlying
Database Service
• @NamedStoredProcedure
SecureYour Services!
• Recommend using OAUTH or LDAP
authentication, generating token
• Utilize JWT to secure endpoints
• MicroProfile JWT
Dozens of Libraries
• PrimeFaces
• ButterFaces
• MyFaces
• OmniFaces (Utilities)
Summary
• Utilize microservices with JPA and JAX-RS
to build database communication
• Create front-ends using JSF, CDI, JAX-RS
• Utilize third party libraries for limitless
options
Learn More

Utilizing JSF Front Ends with Microservices

  • 1.
    Utilizing JSF Front Endsw Microservices Code Smarter Josh Juneau Apress and Java Magazine Author JCP Member, Apache NetBeans Contributor, Java Champion, Jakarta EE Ambassadors
  • 2.
    About Me • Developer,DBA, System Administrator • Author, Speaker, Podcaster • Java Champion • Apache NetBeans Developer • Jakarta EE Ambassadors
  • 3.
    Agenda • Primer onnewer features of Jakarta Server Faces and Jakarta RESTful Web Services • Simple services utilizing Jakarta EE specifications. • Basic Jakarta Server Faces front end to display and update data via RESTful web services. • Incorporation of JSF frameworks to build robust front ends.
  • 4.
    How to GetStarted Today • Download Eclipse GlassFish 5.1.0 (Utilize Payara 5.194+ for JDK 11 support) • https://projects.eclipse.org/projects/ ee4j.glassfish • Include Jakarta EE 8 dependencies into your project • Great examples: • https://github.com/juneau001/JakartaEE-Playground • https://projects.eclipse.org/projects/ee4j.jakartaee-platform/
  • 5.
    Jakarta EE 8Overview • Continued enhancements for productivity and web standards alignment • Better alignment with Java SE 8 • Work towards a better platform for development of microservices
  • 6.
    Jakarta Server Faces •Enhanced CDI Alignment • WebSocket Integration • Ajax Method Invocation • Class LevelValidation • Java 8 Date-Time • Iterable/Map/Custom UIData Support • Component Search Expressions • Radio Button • styleclass on h:column • Basic Support for Extensionless URLs New Features with 2.3
  • 7.
    Utilize Date-Time API Makeuse of the <f:convertDateTime /> tag. New type attribute values on <f:convertDateTime>: • localDate, localTime, localDateTime • offsetTime,offsetDateTime, zonedDateTime
  • 8.
    Jakarta Server Faces3.0 • Removal of old cruft • JSF’s own expression language • Managed Beans • Move more artifacts towards CDI • Action Model (Not to compete with Krazo) • Extensionless Mapping
  • 9.
    Resource Injection Inject JSFartifacts in JSF 2.3, and even possible to inject into other JSF artifacts. @Inject private ExternalContext externalContext; @Inject private ServletContext servletContext;
  • 10.
    How it Works JSF2.3 provides default producers for many of the most commonly used JSF artifacts, therefore, we can now inject rather than hard-code. Converters, validators and behaviors are now also injection targets.
  • 11.
  • 12.
    Jakarta API forRESTful Web Services • Improved CDI Integration • Reactive Client API • Non-Blocking I/O • https://github.com/jax-rs/spec
  • 13.
    • Server SentEvents • One way communication channel • Text protocol,“text/event-stream” media type • Multiple messages • Retry interval Jakarta API for RESTful Web Services
  • 14.
    Building a Simple Service •JAX-RS • JPA • BeanValidation
  • 15.
    Using JSF forFront End • Model: Model Classes • View: Facelets • Controller: CDI Beans • Wire together with Expression Language
  • 16.
    Front End Service •Utilize JAX-RS (RESTful Web Services) client • All database work occurs within the microservice (JPA, EJB if needed) • Utilize JAX-RS to provide data to client
  • 17.
    JAX-RS Client Client client= ClientBuilder.newClient(); WebTarget resource = client.target(clientUri).path(clientService); List<Roster> rosterList = resource.request(javax.ws.rs.core.MediaType.APPLICATION_XML) .get(new GenericType<List<Roster>>() { })
  • 18.
  • 19.
    Communicate (Demo) • Basiccommunication to display database table data
  • 20.
    Writing or Modifying Data •Utilize @PUT and @POST
  • 21.
  • 22.
  • 23.
    Writing or Modifying Data •Demo Utilizing JAX-RS forms and responses
  • 24.
  • 25.
    SecureYour Services! • Recommendusing OAUTH or LDAP authentication, generating token • Utilize JWT to secure endpoints • MicroProfile JWT
  • 26.
    Dozens of Libraries •PrimeFaces • ButterFaces • MyFaces • OmniFaces (Utilities)
  • 27.
    Summary • Utilize microserviceswith JPA and JAX-RS to build database communication • Create front-ends using JSF, CDI, JAX-RS • Utilize third party libraries for limitless options
  • 28.