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
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
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
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
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)
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;
}
}
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