HTML and CSS Reference
In-Depth Information
@FormParam ( "email" ) String email ,
@FormParam ( "phoneNumber" ) String phone ) {
...
//Create a new member class from fields
Member member = new Member ();
member . setName ( name );
member . setEmail ( email );
member . setPhoneNumber ( phone );
try {
//Fire the CDI event
memberEventSrc . fire ( member );
Finally, we set up the WebSocket JavaScript client and safely avoid using the eval()
method to execute the received JavaScript.
...
var location = "ws://192.168.1.101:8081/"
this . _ws = new WebSocket ( location );
....
_onmessage : function ( m ) {
if ( m . data ) {
//check to see if this message is a CDI event
if ( m . data . indexOf ( 'cdievent' ) > 0 ){
try {
//$('log').innerHTML = m.data;
//avoid use of eval...
var event = ( m . data );
event = ( new Function ( "return " + event ))();
event . cdievent . fire ();
} catch ( e ){
alert ( e );
}
} else {
//... append data in the DOM
}
}
},
Here is the JavaScript code that listens for the CDI event and executes the necessary
client-side code:
window . addEventListener ( 'memberEvent' , function ( e ) {
alert ( e . name + ' just registered!' );
}, false );
As you can see, this is a very prototyped approach to achieve a running WebSocket
server, but it's a step forward in adding a usable programming layer on top of the Web‐
Socket protocol.
Search WWH ::




Custom Search