SlideShare a Scribd company logo
1 of 41
If AngularJS is what should have been
HTML, if CDI is what should have been
JavaEE, AngularBeans is what should
be JSF!
Agenda
• “web applications”, new needs
(frameworks view)
• AngularBeans
• Q&A
“web applications”, new needs
Single page web application (SPA)
& Thin server concept
Real-time & fall back
Json & JsonRPC
Client Server
Initial Req
GET,POST…
Classic approach
HTML
Rendrering
Page reloading
Sometes req
resource (via
ajax )
Service
Backend
HTML
Generation
UI logic
MVC
Validations…
Sessions care
Client Server
Initial Req
GET,POST…
SPA approach
HTML
Rendrering
Page
reloading
HTML
Rendrering
Data updates
UI logic
Validation
Session data
Simulated
naviguation
(via #)
Thin Server
Backend
Rest
JsonRPC
Wsocket
Comet
……
RT –WebAPP : WebSockets
SocketIO /SockJS:
• Abstracts WebSocket communications to
automatically fall back to flash streaming
or long-polling when necessary (on either
server or client)
• Adds features like heartbeats, timeouts,
and disconnection support not provided in
WebSocket API
JSON/JSON RPC
{
{
"is": ["compact", "readable"]
"web_service": "JS native object"
"enough" : "for majority of needs"
}
}
REST (Representational State
Transfer)
Restfull HTTP / Restfull Architectures
HTTP Methods (GET/POST/DELETE…) as
CRUD
BookMarking 
Stateless By Design  scalability+
JSF
JSF /But
Life cycle -> good
extentions points but
give us a more complex
and errors-prone
framework
Scalability (-)
HTML5 (-) even with
passthrow.
Facelets -> xhtml
Server Side validation(-)
bookMarking (-)
Server Side UI-Logic (-)
Performances 
JS framework
MVC/MVVM/MV*
2 Ways DataBinding
Modules
Services
Controllers
Events
What we need ?
Single framework that care about:
SPA & Thin Server concepts
Pure HTML5 support (not a sever side
generated HTML5)  we can use tools as
bower, grunt, yeoman generators…
Real Time support + fall back when needed
“clear and cleans” url’s
JavaEE7 (+)
AngularBeans
AngularJS  JavaEE (CDI) Backend
Json RPC
Bean Validation
URL Based File Upload
CDI Bean  Angular Services
CDI EventsAngular Event
Real Time @RealTime & Broadcasting
System
ModelQuery (server->client)
SockJs auto detection and Native support!
AngularBeans : Requirements
JDK 7 (or+)
JavaEE7 (or+) Web profile or full profile AS.
AngularJS lib
--------------------
First production-ready release:
1.0.1  sept 2015
AngularBeans: principle
@AngularBean
1
@AngularBean
2
NG
Service 1
NG
Service 2
NG ctrl
NG ctrl
NG ctrl
@ Other CDI
Bean
« Singleton »
« Singleton »
Dependency
injectionDependency
injection
AngularBeans CDI scopes :
@RequestScoped
@ApplicationScoped
@NGSesionScoped :
classic @SessionScoped is bound only to the classic
HTTP session or the websocket session but only one will be
active  we cannot open a conversation with the same CDI
bean that include a http Get request and after that a
websocket call for example.
But with @NGSessionScoped  shared context between
websocket calls and classic http methods calls.
we can have many websockets sessions (if many browser
tabs open for example ) + 1 http session  all grouped in a
single NG Session)
AngularBeans : HTML head & fallback feature
Angulars beans will auto detect that and will use a
sockJS server end point to exploit sockJS features/
else it will use a JSR356 raw Websocket for real
time interactions (no fall back feature then)
angular-beans.js will be generated dynamically
AngularBeans : my first bean (style 1)
@AngularBean
@RequestScoped
public class CalcBean {
private int a, b;
private int result;
@NGModel
public int getA() {
return a;
}
@NGModel
public int getB() {
return b;
}
@NGModel
public int getResult() {
return result;
}
@GET
@NGSubmit(backEndModels = { "a", "b" })
@NGReturn(model = "result")
public int add() {
result = a + b;
return result;
}
public void setA(int a) {
this.a = a;
}
public void setB(int b) {
this.b = b;
}
}
Get method (can be @Post, @Put, @Delete or
@RealTime
If any: dfault->: @Get
Array of the server side models to be
synchronused with the js proxy state, if
«*» all properties marqued @Model will
be updated (before method call ofc)
Front ent Model to be synchronied with
the return of the method
Additional attribute ->
,updates=« » : array of other front end
models to be updated too
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
src="bower_components/angularjs/angular.js"></script>
<script type="text/javascript" src="angular-beans.js"></script>
<script type="text/javascript">
var myApp = angular.module("myApp", [ "angularBeans" ]);
myApp.controller('calcCtrl', function($scope, calcBean) {
$scope.clacBean = calcBean;
});
</script>
</head>
AngularBeans : my first bean (style 1) :HTML
module generated by AngularBeans
CalcBean is now an injectable service
<body ng-app="myApp">
<div ng-controller="calcCtrl">
<label>a:</label>
<input type="text" ng-model="clacBean.a">
<label>b:</label>
<input type="text" ng-model="clacBean.b">
<button ng-click="clacBean.add()">send</button>
<br />
<h2>Result: {{clacBean.result}}</h2>
</div>
</body>
</html>
AngularBeans : my first bean (style 1) :HTML
Diect bean call
AngularBeans : my first bean (style 1) : result
@AngularBean
@RequestScoped
public class CalcBean {
@GET
public int add(int a, int b){
return a + b;
}
}
AngularBeans : my first bean (style 2)
Args passed via RPC style (can be primitves,
objects, arrays or var args)
AngularBeans : my first bean (style 2) :HTML
<script type="text/javascript">
var myApp = angular.module("myApp", [
"angularBeans" ]);
myApp.controller('calcCtrl', function($scope,
calcBean) {
$scope.add = function(a,b) {
calcBean.add(a,b).then(function(data){
$scope.result=data;
}
);
}
});
</script>
AngularBeans : my first bean (style 2) :HTML
<body ng-app="myApp">
<div ng-controller="calcCtrl">
<label>a:</label>
<input type="text" ng-model="a">
<label>b:</label>
<input type="text" ng-model="b">
<button ng-click="add(a,b)">send</button>
<br />
<h2>Result: {{result}}</h2>
</div>
</body>
AngularBeans : my first bean (with binding)
:HTML
<script type="text/javascript">
var myApp = angular.module("myApp", [ "angularBeans" ]);
myApp.controller('calcCtrl', function($scope, calcBean) {
angularBeans.bind($scope,calcBean,["result"]);
});
</script>
Scope will be auto synchronized with the bean proxy (the
service) state, this function take as argument an array of
the properties to be bound, in this case « result » is the
main return so we must add @NGReturn(model="result")
on the add() method of the bean
AngularBeans : my first bean (adding log)
import angularBeans.log.NGLogger;
import angularBeans.log.NGLogger.Level;
@AngularBean
@RequestScoped
public class CalcBean {
@Inject
NGLogger logger;
@GET
@NGReturn(model = "result")
public int add(int a, int b) {
logger.log(Level.WARN, "a=%s , b=%s , a+b= %s", a, b, a + b);
return a + b;
}
}
AngularBeans : my first bean (adding log)
AngularBeans : my first bean
(@NGPostconstruct)
@Inject
NGLogger logger;
@NGPostConstruct
public void init(){
logger.log
(Level.INFO, "this method will be called at the service
creation");
}
AngularBeans : my first bean
(ModelQuey)
package org.angularbeans.example;
public class Message {
private String summary;
private String detail;
public Message(String summary, String detail) {
super();
this.summary = summary;
this.detail = detail;
}
}
AngularBeans : my first bean
(ModelQuey)
@AngularBean
@RequestScoped
public class CalcBean {
@Inject
NGLogger logger;
@Inject
ModelQuery modelQuery;
@NGPostConstruct
public void init() {
logger.log(Level.INFO,
"this method will be called
at the service creation");
}
@GET
@NGReturn(model = "result")
public int add(int a, int b) {
logger.log(Level.WARN, "a=%s ,
b=%s , a+b= %s", a, b, a + b);
modelQuery.pushTo("messages",
new Message("attention",
"calculation...")).setProperty("ti
me",
new Date());
;
return a + b;
}
}
AngularBeans : my first bean
(ModelQuey) :HTML
myApp.controller('calcCtrl', function($scope, calcBean) {
angularBeans.bind($scope,calcBean,["result","messages","time"])
;
});
<h2>Result: {{result}}</h2>
<ul ng-repeat="m in messages">
<li>{{m.summary}} - {{m.detail}}</li>
</ul>
{{time}}
AngularBeans : my first bean
(ModelQuey)
ModelQuery’s are simply a query’s from back end to
front end to update their models
AngularBeans : my first bean
real time & events
@Inject
RealTimeClient client;
@RealTime
public void notifyOthers(){
RealTimeMessage rtMessage=new
RealTimeMessage().set("notification", "someData");
client.broadcast("calculationEvent",rtMessage, false);
}
This method will be called via
websocket (or fall back strategy)
Broadcast the message to all
connected sessions (can also
broadcast a QueryModel)
If false the sender will also receive the
event
myApp.controller('calcCtrl', function($scope,
calcBean) {
angularBeans.bind($scope,calcBean,["result","messages"
,"time"]);
$scope.$on("calculationEvent",function(event,data){
alert(data.notification);
});
});
AngularBeans : my first bean
real time & events
AngularBeans : others examples
Form validation :
https://gist.github.com/bessemHmidi/408438a2eae5
24f0348f
Files upload & LobWrapper (binary data like images):
https://gist.github.com/bessemHmidi/5d13d6216923
6bc17a32
http://bessemhmidi.github.io/AngularBeans/
THANK YOU!

More Related Content

What's hot

GR8Conf 2011: Grails, how to plug in
GR8Conf 2011: Grails, how to plug inGR8Conf 2011: Grails, how to plug in
GR8Conf 2011: Grails, how to plug in
GR8Conf
 

What's hot (20)

Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
GR8Conf 2011: Grails, how to plug in
GR8Conf 2011: Grails, how to plug inGR8Conf 2011: Grails, how to plug in
GR8Conf 2011: Grails, how to plug in
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Spring 4 Web App
Spring 4 Web AppSpring 4 Web App
Spring 4 Web App
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Making the Most of Your Gradle Build
Making the Most of Your Gradle BuildMaking the Most of Your Gradle Build
Making the Most of Your Gradle Build
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
Java REST API Framework Comparison - UberConf 2021
Java REST API Framework Comparison - UberConf 2021Java REST API Framework Comparison - UberConf 2021
Java REST API Framework Comparison - UberConf 2021
 
Apache Lucene for Java EE Developers
Apache Lucene for Java EE DevelopersApache Lucene for Java EE Developers
Apache Lucene for Java EE Developers
 
The world of gradle - an introduction for developers
The world of gradle  - an introduction for developersThe world of gradle  - an introduction for developers
The world of gradle - an introduction for developers
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
 
COScheduler
COSchedulerCOScheduler
COScheduler
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache Geode
 
Web components with java by Haijian Wang
Web components with java by Haijian WangWeb components with java by Haijian Wang
Web components with java by Haijian Wang
 

Similar to Angular beans

OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
mfrancis
 
SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...
Liam Cleary [MVP]
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 

Similar to Angular beans (20)

Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
 
OSGi and Spring Data for simple (Web) Application Development
OSGi and Spring Data  for simple (Web) Application DevelopmentOSGi and Spring Data  for simple (Web) Application Development
OSGi and Spring Data for simple (Web) Application Development
 
Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for DevelopersLiferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
 
Javascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web AppsJavascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web Apps
 
Angular Js Basics
Angular Js BasicsAngular Js Basics
Angular Js Basics
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative Webtechnologie
 
Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New Features
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
 
SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...
 
MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)MEAN - Notes from the field (Full-Stack Development with Javascript)
MEAN - Notes from the field (Full-Stack Development with Javascript)
 
Angular js
Angular jsAngular js
Angular js
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
 
Build your website with angularjs and web apis
Build your website with angularjs and web apisBuild your website with angularjs and web apis
Build your website with angularjs and web apis
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 
DevOps &lt;3 node.js
DevOps &lt;3 node.jsDevOps &lt;3 node.js
DevOps &lt;3 node.js
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Angular beans

  • 1. If AngularJS is what should have been HTML, if CDI is what should have been JavaEE, AngularBeans is what should be JSF!
  • 2. Agenda • “web applications”, new needs (frameworks view) • AngularBeans • Q&A
  • 4. Single page web application (SPA) & Thin server concept Real-time & fall back Json & JsonRPC
  • 5. Client Server Initial Req GET,POST… Classic approach HTML Rendrering Page reloading Sometes req resource (via ajax ) Service Backend HTML Generation UI logic MVC Validations… Sessions care
  • 6. Client Server Initial Req GET,POST… SPA approach HTML Rendrering Page reloading HTML Rendrering Data updates UI logic Validation Session data Simulated naviguation (via #) Thin Server Backend Rest JsonRPC Wsocket Comet ……
  • 7. RT –WebAPP : WebSockets
  • 8. SocketIO /SockJS: • Abstracts WebSocket communications to automatically fall back to flash streaming or long-polling when necessary (on either server or client) • Adds features like heartbeats, timeouts, and disconnection support not provided in WebSocket API
  • 9. JSON/JSON RPC { { "is": ["compact", "readable"] "web_service": "JS native object" "enough" : "for majority of needs" } }
  • 10. REST (Representational State Transfer) Restfull HTTP / Restfull Architectures HTTP Methods (GET/POST/DELETE…) as CRUD BookMarking  Stateless By Design  scalability+
  • 11. JSF
  • 12. JSF /But Life cycle -> good extentions points but give us a more complex and errors-prone framework Scalability (-) HTML5 (-) even with passthrow. Facelets -> xhtml Server Side validation(-) bookMarking (-) Server Side UI-Logic (-) Performances 
  • 13. JS framework MVC/MVVM/MV* 2 Ways DataBinding Modules Services Controllers Events
  • 14. What we need ? Single framework that care about: SPA & Thin Server concepts Pure HTML5 support (not a sever side generated HTML5)  we can use tools as bower, grunt, yeoman generators… Real Time support + fall back when needed “clear and cleans” url’s
  • 16.
  • 17. AngularBeans AngularJS  JavaEE (CDI) Backend Json RPC Bean Validation URL Based File Upload CDI Bean  Angular Services CDI EventsAngular Event Real Time @RealTime & Broadcasting System ModelQuery (server->client) SockJs auto detection and Native support!
  • 18. AngularBeans : Requirements JDK 7 (or+) JavaEE7 (or+) Web profile or full profile AS. AngularJS lib -------------------- First production-ready release: 1.0.1  sept 2015
  • 19. AngularBeans: principle @AngularBean 1 @AngularBean 2 NG Service 1 NG Service 2 NG ctrl NG ctrl NG ctrl @ Other CDI Bean « Singleton » « Singleton » Dependency injectionDependency injection
  • 20. AngularBeans CDI scopes : @RequestScoped @ApplicationScoped @NGSesionScoped : classic @SessionScoped is bound only to the classic HTTP session or the websocket session but only one will be active  we cannot open a conversation with the same CDI bean that include a http Get request and after that a websocket call for example. But with @NGSessionScoped  shared context between websocket calls and classic http methods calls. we can have many websockets sessions (if many browser tabs open for example ) + 1 http session  all grouped in a single NG Session)
  • 21. AngularBeans : HTML head & fallback feature Angulars beans will auto detect that and will use a sockJS server end point to exploit sockJS features/ else it will use a JSR356 raw Websocket for real time interactions (no fall back feature then) angular-beans.js will be generated dynamically
  • 22. AngularBeans : my first bean (style 1) @AngularBean @RequestScoped public class CalcBean { private int a, b; private int result; @NGModel public int getA() { return a; } @NGModel public int getB() { return b; } @NGModel public int getResult() { return result; } @GET @NGSubmit(backEndModels = { "a", "b" }) @NGReturn(model = "result") public int add() { result = a + b; return result; } public void setA(int a) { this.a = a; } public void setB(int b) { this.b = b; } } Get method (can be @Post, @Put, @Delete or @RealTime If any: dfault->: @Get Array of the server side models to be synchronused with the js proxy state, if «*» all properties marqued @Model will be updated (before method call ofc) Front ent Model to be synchronied with the return of the method Additional attribute -> ,updates=« » : array of other front end models to be updated too
  • 23. <!DOCTYPE html> <html> <head> <script type="text/javascript" src="bower_components/angularjs/angular.js"></script> <script type="text/javascript" src="angular-beans.js"></script> <script type="text/javascript"> var myApp = angular.module("myApp", [ "angularBeans" ]); myApp.controller('calcCtrl', function($scope, calcBean) { $scope.clacBean = calcBean; }); </script> </head> AngularBeans : my first bean (style 1) :HTML module generated by AngularBeans CalcBean is now an injectable service
  • 24. <body ng-app="myApp"> <div ng-controller="calcCtrl"> <label>a:</label> <input type="text" ng-model="clacBean.a"> <label>b:</label> <input type="text" ng-model="clacBean.b"> <button ng-click="clacBean.add()">send</button> <br /> <h2>Result: {{clacBean.result}}</h2> </div> </body> </html> AngularBeans : my first bean (style 1) :HTML Diect bean call
  • 25. AngularBeans : my first bean (style 1) : result
  • 26. @AngularBean @RequestScoped public class CalcBean { @GET public int add(int a, int b){ return a + b; } } AngularBeans : my first bean (style 2) Args passed via RPC style (can be primitves, objects, arrays or var args)
  • 27. AngularBeans : my first bean (style 2) :HTML <script type="text/javascript"> var myApp = angular.module("myApp", [ "angularBeans" ]); myApp.controller('calcCtrl', function($scope, calcBean) { $scope.add = function(a,b) { calcBean.add(a,b).then(function(data){ $scope.result=data; } ); } }); </script>
  • 28. AngularBeans : my first bean (style 2) :HTML <body ng-app="myApp"> <div ng-controller="calcCtrl"> <label>a:</label> <input type="text" ng-model="a"> <label>b:</label> <input type="text" ng-model="b"> <button ng-click="add(a,b)">send</button> <br /> <h2>Result: {{result}}</h2> </div> </body>
  • 29. AngularBeans : my first bean (with binding) :HTML <script type="text/javascript"> var myApp = angular.module("myApp", [ "angularBeans" ]); myApp.controller('calcCtrl', function($scope, calcBean) { angularBeans.bind($scope,calcBean,["result"]); }); </script> Scope will be auto synchronized with the bean proxy (the service) state, this function take as argument an array of the properties to be bound, in this case « result » is the main return so we must add @NGReturn(model="result") on the add() method of the bean
  • 30. AngularBeans : my first bean (adding log) import angularBeans.log.NGLogger; import angularBeans.log.NGLogger.Level; @AngularBean @RequestScoped public class CalcBean { @Inject NGLogger logger; @GET @NGReturn(model = "result") public int add(int a, int b) { logger.log(Level.WARN, "a=%s , b=%s , a+b= %s", a, b, a + b); return a + b; } }
  • 31. AngularBeans : my first bean (adding log)
  • 32. AngularBeans : my first bean (@NGPostconstruct) @Inject NGLogger logger; @NGPostConstruct public void init(){ logger.log (Level.INFO, "this method will be called at the service creation"); }
  • 33. AngularBeans : my first bean (ModelQuey) package org.angularbeans.example; public class Message { private String summary; private String detail; public Message(String summary, String detail) { super(); this.summary = summary; this.detail = detail; } }
  • 34. AngularBeans : my first bean (ModelQuey) @AngularBean @RequestScoped public class CalcBean { @Inject NGLogger logger; @Inject ModelQuery modelQuery; @NGPostConstruct public void init() { logger.log(Level.INFO, "this method will be called at the service creation"); } @GET @NGReturn(model = "result") public int add(int a, int b) { logger.log(Level.WARN, "a=%s , b=%s , a+b= %s", a, b, a + b); modelQuery.pushTo("messages", new Message("attention", "calculation...")).setProperty("ti me", new Date()); ; return a + b; } }
  • 35. AngularBeans : my first bean (ModelQuey) :HTML myApp.controller('calcCtrl', function($scope, calcBean) { angularBeans.bind($scope,calcBean,["result","messages","time"]) ; }); <h2>Result: {{result}}</h2> <ul ng-repeat="m in messages"> <li>{{m.summary}} - {{m.detail}}</li> </ul> {{time}}
  • 36. AngularBeans : my first bean (ModelQuey) ModelQuery’s are simply a query’s from back end to front end to update their models
  • 37. AngularBeans : my first bean real time & events @Inject RealTimeClient client; @RealTime public void notifyOthers(){ RealTimeMessage rtMessage=new RealTimeMessage().set("notification", "someData"); client.broadcast("calculationEvent",rtMessage, false); } This method will be called via websocket (or fall back strategy) Broadcast the message to all connected sessions (can also broadcast a QueryModel) If false the sender will also receive the event
  • 39. AngularBeans : others examples Form validation : https://gist.github.com/bessemHmidi/408438a2eae5 24f0348f Files upload & LobWrapper (binary data like images): https://gist.github.com/bessemHmidi/5d13d6216923 6bc17a32