activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmoulliard <cmoulli...@gmail.com>
Subject Re: Where the Message object (javascript) of amq.js is defined ?
Date Wed, 22 Oct 2008 13:33:17 GMT

Many thanks Dejan.

It could be interesting to update the ajax.html page with the above text in
order to help all the users that we are ;)

KR,

Charles 


Dejan Bosanac-3 wrote:
> 
> Hi Charles,
> 
> stock portfolio example sends XML in a text message to the Ajax client.
> Therefore, you'll get the response like this (full body).
> 
> <ajax-response>
> <response id='stocks' destination='topic://STOCKS.*' ><price
> stock='BEAS' bid='94.08395193508605' offer='94.17803588702112'
> movement='up'/></response>
> </ajax-response>
> 
> the "message object" you see is just the <price ... /> xml text and
> getAttribute() is JavaScript way of handling XML tag attributes.
> So, there is no "definition" of message object, it's just what you send
> to the broker; text if it is a TextMessage or object.toString in case of
> object message.
> 
> Also you can find _amq.js which contains the whole Ajax JavaScript logic
> here
> 
> http://svn.apache.org/viewvc/activemq/trunk/activemq-web/src/main/resources/org/apache/activemq/web/_amq.js?view=markup
> 
> Cheers
> 
> -- 
> Dejan Bosanac
> 
> 
> http://www.ttmsolutions.com - get a free ActiveMQ user guide
> 
> ActiveMQ in Action - http://www.manning.com/snyder/
> Scripting in Java - http://www.scriptinginjava.net
> 
> 
> 
> 
> cmoulliard wrote:
>> Hi,
>>
>> Additional question : What is the javascript class of the message
>> returned
>> (DOM, XMLHTTPResuest, ....) ?
>>
>> The existing doc does not help us because in the two example, we saw that
>> we
>> can use message.getAttribute or message.getChildNodes[0], ... ?
>>
>> KR,
>>
>> Charles Moulliard
>>
>>
>> cmoulliard wrote:
>>   
>>> Hi,
>>>
>>> I would like to know where the javascript object Message used by
>>> AJAX/ActiveMq in a HTML page is defined ? I see in the portfolio example
>>> that we can use the following method "message.getAttribute('stock')" to
>>> access part of the xml message returned by the queue engine through the
>>> MessageListenerServlet but I would like to know what are the methods /
>>> variables available for this message object (which is normally a mirror
>>> of
>>> the jax.jms.Message object) ?
>>>
>>> To be more precise, here is a copy/paste of the portfolio.js script of
>>> the
>>> example where message appears at the line _price: function(message)
>>>
>>> var priceHandler = {
>>>   _price: function(message) {
>>>     if (message != null) {
>>>       var price = parseFloat(message.getAttribute('bid'))
>>>       var symbol = message.getAttribute('stock')
>>>       var movement = message.getAttribute('movement')
>>>       if (movement == null) {
>>> 	        movement = 'up'
>>>       }
>>> 	    
>>>       var row = document.getElementById(symbol)
>>>       if (row) {
>>> 		    // perform portfolio calculations
>>> 		    var value = asFloat(find(row, 'amount')) * price
>>> 		    var pl = value - asFloat(find(row, 'cost'))
>>> 		    
>>> 		    // now lets update the HTML DOM
>>> 		    find(row, 'price').innerHTML = fixedDigits(price, 2)
>>> 		    find(row, 'value').innerHTML = fixedDigits(value, 2)
>>> 		    find(row, 'pl').innerHTML    = fixedDigits(pl, 2)
>>> 		    find(row, 'price').className = movement
>>> 		    find(row, 'pl').className    = pl >= 0 ? 'up' : 'down'
>>>       }
>>>     }
>>>   }
>>> };
>>>
>>> function portfolioPoll(first)
>>> {
>>>    if (first)
>>>    {
>>>      amq.addListener('stocks','topic://STOCKS.*',priceHandler._price);
>>>    }
>>> }
>>>
>>> amq.addPollHandler(portfolioPoll);
>>>
>>> Remark : addtiaional question
>>> - Who will cal the function portfolioPoll(first) function ?
>>> - How is the parameter first which is a boolean setted ?
>>>
>>> KR,
>>>
>>> Charles Moulliard
>>>
>>>     
>>
>>
>> -----
>> Enterprise Architect
>>
>> Xpectis
>> 12, route d'Esch
>> L-1470 Luxembourg
>>
>> Phone +352 25 10 70 470
>> Mobile +352 621 45 36 22
>>
>> e-mail : cmoulliard@xpectis.com
>> web site :  www.xpectis.com www.xpectis.com 
>> My Blog :  http://cmoulliard.blogspot.com/
>> http://cmoulliard.blogspot.com/  
>>   
> 
> 
> 
> 


-----
Enterprise Architect

Xpectis
12, route d'Esch
L-1470 Luxembourg

Phone +352 25 10 70 470
Mobile +352 621 45 36 22

e-mail : cmoulliard@xpectis.com
web site :  www.xpectis.com www.xpectis.com 
My Blog :  http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/  
-- 
View this message in context: http://www.nabble.com/Where-the-Message-object-%28javascript%29-of-amq.js-is-defined---tp20090852p20110798.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message