<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CarbonRider &#187; Flex</title>
	<atom:link href="http://www.carbonrider.com/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.carbonrider.com</link>
	<description>You make a matrix, you define the limits.</description>
	<lastBuildDate>Wed, 08 Sep 2010 17:33:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Flex DataGrid &#8211; Data updates not reflected</title>
		<link>http://flex.carbonrider.com/2010/08/24/flex-datagrid-data-updates-not-reflected/</link>
		<comments>http://flex.carbonrider.com/2010/08/24/flex-datagrid-data-updates-not-reflected/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 16:03:14 +0000</pubDate>
		<dc:creator>Carbon Rider</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Advanced Datagrid]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[Flex collection update]]></category>
		<category><![CDATA[Flex DataGrid]]></category>
		<category><![CDATA[ItemEditor Collection Update]]></category>

		<guid isPermaLink="false">http://www.carbonrider.com/?p=324</guid>
		<description><![CDATA[Flex datagrid is nice option to display data in tabular format and with built-in features like sort, rearrange column position and customize each columns with renderers/editors, it makes developers life easy to built user friendly application in quick time.  But most of the time, those who have coded in Flex, must have noticed that the datagrid [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fflex.carbonrider.com%2F2010%2F08%2F24%2Fflex-datagrid-data-updates-not-reflected%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fflex.carbonrider.com%2F2010%2F08%2F24%2Fflex-datagrid-data-updates-not-reflected%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Flex datagrid is nice option to display data in tabular format and with built-in features like sort, rearrange column position and customize each columns with renderers/editors, it makes developers life easy to built user friendly application in quick time.  But most of the time, those who have coded in Flex, must have noticed that the datagrid just doesnt work properly when row information is updated. Consider following scenario.</p>
<p>1. Datagrid uses ItemEditor to update Collection bound as dataprovider.<br />
2. A change in value of one of the column, involves updates to values displayed in other columns.</p>
<p>In 2nd step, user may change value in one of the column, which will internally result in change in value displayed in other columns. One can easily achieve that using itemEditEnd event but most of the time the updates are not reflected. Consider following code</p>
<pre class="brush: xml;">
<mx:ArrayCollection id="dgArr">
		<mx:Array>
			<mx:Object firstName="Jake" lastName="Tyler" gross="" commPer="" comm="" net="" markAsReadOnly=""/>
			<mx:Object firstName="Ryan" lastName="McCarthy" gross="" commPer="" comm="" net=""  markAsReadOnly=""/>
			<mx:Object firstName="Jill" lastName="Miller" gross="" commPer="" comm="" net=""  markAsReadOnly=""/>
			<mx:Object firstName="John" lastName="Rico" gross="" commPer="" comm="" net=""  markAsReadOnly=""/>
			<mx:Object firstName="Diz" lastName="Watson" gross="" commPer="" comm="" net=""  markAsReadOnly=""/>
			<mx:Object firstName="Lolo" lastName="Hurley" gross="" commPer="" comm="" net=""  markAsReadOnly=""/>
		</mx:Array>
	</mx:ArrayCollection>

	<mx:AdvancedDataGrid dataProvider="{dgArr}" x="100" y="100"
		editable="true" rowCount="5" id="dg"
		itemEditEnd="calculateCommission(event)">
		<mx:groupedColumns>
			<mx:AdvancedDataGridColumn headerText="Read Only" dataField="markAsReadOnly" headerWordWrap="true" editorDataField="selected" editable="true" itemRenderer="mx.controls.CheckBox" rendererIsEditor="true"/>
			<mx:AdvancedDataGridColumn headerText="First Name" dataField="firstName" editable="false"/>
			<mx:AdvancedDataGridColumn headerText="Last Name" dataField="lastName" editable="false"/>
			<mx:AdvancedDataGridColumnGroup headerText="Commission Calculation">
				<mx:AdvancedDataGridColumn dataField="gross" headerText="Gross" itemRenderer="mx.controls.TextInput" rendererIsEditor="true"/>
				<mx:AdvancedDataGridColumn dataField="commPer" headerText="Comm %" itemRenderer="mx.controls.TextInput" rendererIsEditor="true"/>
				<mx:AdvancedDataGridColumn dataField="comm" headerText="Comm" itemRenderer="mx.controls.TextInput" rendererIsEditor="true"/>
				<mx:AdvancedDataGridColumn dataField="net" headerText="Net" itemRenderer="mx.controls.TextInput" rendererIsEditor="true"/>
			</mx:AdvancedDataGridColumnGroup>
		</mx:groupedColumns>
	</mx:AdvancedDataGrid>
</pre>
<p><span id="more-324"></span><br />
Above code just binds one ArrayCollection to datagrid and editable values are displayed in textboxes. The basic requirement is that whenever user enters &#8220;Gross&#8221; and &#8220;Commission %&#8221;, the &#8220;Commission&#8221; and &#8220;Net&#8221; column should be updated. The logic to achieve this is defined in following function</p>
<pre class="brush: javascript;">
private function calculateCommission(evt:AdvancedDataGridEvent):void
{
	if(evt.reason == DataGridEventReason.CANCELLED)
		return;
	var dtIndex:int = evt.currentTarget.selectedIndex;
	var dtField:String = evt.dataField;

	var gross:*, commPer:*, comm:*, net:*;
	var dataGross:* = evt.itemRenderer.data.gross;
	var dataCommPer:* = evt.itemRenderer.data.commPer;
	var dataComm:* = evt.itemRenderer.data.comm;
	var dataNet:* = evt.itemRenderer.data.net;
	switch(dtField)
	{
		case "gross":
			trace("gross column edited.");
			gross = evt.currentTarget.itemEditorInstance.text;
			if( (dataCommPer != null) &#038;&#038; (dataCommPer!="") )
			{
				comm = (gross * dataCommPer) / 100;
				net = gross - comm;
			}else if( (dataComm != null) &#038;&#038; (dataComm!=""))
			{
				commPer = (dataComm * 100) / gross;
				net = gross - dataComm;
			}else{
				net = gross;
			}
			break;
		case "commPer":
			trace("comm % column edited.");
			commPer = evt.currentTarget.itemEditorInstance.text;
			if( (dataGross != null) &#038;&#038; (dataGross!="") )
			{
				comm = dataGross * (commPer / 100);
				net = dataGross - comm;
			}
			break;
		case "comm":
			trace("comm column edited.");
			comm = evt.currentTarget.itemEditorInstance.text;
			if( (dataGross != null) &#038;&#038; (dataGross!="") )
			{
				commPer = (100 * comm) / dataGross;
				net = dataGross - comm;
			}
			break;
		case "net":
			trace("net column edited.");
			net = evt.currentTarget.itemEditorInstance.text;
			break;
		}

		var item:Object = evt.currentTarget.dataProvider.getItemAt(dtIndex);

		if(gross!=null)
			item.gross = gross;
		if(commPer!=null)
			item.commPer = commPer;
		if(comm!=null)
			item.comm = comm;
		if(net!=null)
			item.net = net;
		evt.currentTarget.dataProvider.itemUpdated(item);
		}
</pre>
<p>(Note that above code is not completed but used for illustration purpose). Above code updates values in respective properties of given item and invokes itemUpdated function on underlying ArrayCollection. If you run the application, you might notice that the application behaves unexpectadly. Sometimes the values are updated and sometimes it wont update value. To resolve this issue, comment &#8220;itemUpdated&#8221; function call and add following code.</p>
<pre class="brush: javascript;">
var colEvent:CollectionEvent = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE,
true,false, CollectionEventKind.UPDATE);
colEvent.items = [item];
colEvent.location =  dtIndex;
(evt.currentTarget.dataProvider as ArrayCollection).dispatchEvent(colEvent);
</pre>
<p>You will now notice that everytime you update the column values, the changes are reflected properly. Above code will work in all scenarios, except one. To simulate that issue, perform following steps</p>
<p>1. Enter some values in all the rows.<br />
2. Click on textbox displayed for &#8220;Commission&#8221; column of 1st row.<br />
3. Without changing any value, now select &#8220;Gross&#8221; column textbox of 2nd row with left button of mouse.<br />
4. Change the value displayed in &#8220;Gross&#8221; textbox of 2nd row and tab out. You will notice that tab will focus on 1st row rather than moving to next textbox.</p>
<p>The reason behind such unexpected behavior is that when user directly selects the value in any of the editable column, the datagrid controls is not able to track the event and hence the itemEditedPosition property is not set.<br />
To make above code work, you should modify the itemRenderer attribute in above code and create one mxml renderer component. Refer to following code.</p>
<pre class="brush: xml;">
<mx:TextInput xmlns:mx="http://www.adobe.com/2006/mxml" focusIn="setItemEditedPosition(event)">
	<mx:Script>
		<![CDATA[
			import mx.controls.AdvancedDataGrid;
			import mx.controls.listClasses.IListItemRenderer;
			import mx.controls.DataGrid;
			private function setItemEditedPosition(evt:FocusEvent):void
			{
				var dg:AdvancedDataGrid = this.listData.owner as AdvancedDataGrid;

				dg.editedItemPosition = {rowIndex: this.listData.rowIndex,columnIndex:this.listData.columnIndex};
			}
		]]&gt;
	</mx:Script>
</mx:TextInput>
</pre>
<p>I would name this file as &#8220;AmountInput.mxml&#8221; and change itemRenderer Attribute of the datagridcolumn to point this new component.<br />
Build the project and run it. Now you would notice that the data updations are reflected properly.</p>
<p>Hope this helps !</p>
<p>Updated : Thought of putting source code for this example, to download the source code just <a href="http://www.carbonrider.com/wp-content/uploads/2010/09/src.zip">click here</a>. I am using Flex SDK 3.4 with target flash player version as 10.0.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://flex.carbonrider.com/2010/08/24/flex-datagrid-data-updates-not-reflected/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Item Editor &#8211; Tabbing &#8211; Flex Datagrid</title>
		<link>http://flex.carbonrider.com/2009/12/19/item-editor-tabbing/</link>
		<comments>http://flex.carbonrider.com/2009/12/19/item-editor-tabbing/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 15:30:00 +0000</pubDate>
		<dc:creator>Carbon Rider</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[custom item editor tabbing]]></category>
		<category><![CDATA[DataGrid Item Editor]]></category>
		<category><![CDATA[DataGrid tabbing]]></category>
		<category><![CDATA[Flex DataGrid]]></category>
		<category><![CDATA[Item Editor tabbing]]></category>

		<guid isPermaLink="false">http://www.carbonrider.com/?p=160</guid>
		<description><![CDATA[Most of you, must have customized Flex DataGrid using custom item editors, may be to format an information or to group multiple controls in one column. Customizing appearance of DataGrid cells is one of the powerful feature of Flex and comes to the rescue of developer. This article discusses one of the problem faced by [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fflex.carbonrider.com%2F2009%2F12%2F19%2Fitem-editor-tabbing%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fflex.carbonrider.com%2F2009%2F12%2F19%2Fitem-editor-tabbing%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Most of you, must have customized Flex DataGrid using custom item editors, may be to format an information or to group multiple controls in one column. Customizing appearance of DataGrid cells is one of the powerful feature of Flex and comes to the rescue of developer. This article discusses one of the problem faced by the developers while implementing customized item editor.</p>
<p><span id="more-160"></span></p>
<p>Consider an example where in 3 columns are added to DataGrid as<br />
1. Customer ID<br />
2. Customer Name<br />
3. No. of Orders</p>
<p>All of these columns should be editable and a search icon should be placed next to customer name textbox. Users should be able to search customer name by clicking on search icon.</p>
<p>Usually, developers tend to use custom item editor along with HBox or Canvas to achieve this requirement. But there are problems of using HBox or Canvas as a root tag for Item Editor. If your users mostly like to use Keyboard over mouse, you will notice that &#8220;Tab&#8221; do not work as per expectation. Users will find your application keyboard-unfriendly and may get frustrated due to forceful use of mouse. Compile following code and just tab through grids, you will notice the problem.</p>
<pre class="brush: xml;">
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:ArrayCollection id="dgProvider">
		<mx:Array>
			<mx:Object custId="C1191" custName="John Michael" noOfOrder="10"/>
			<mx:Object custId="C2252" custName="Ginny" noOfOrder="5"/>
			<mx:Object custId="C3442" custName="Jeremy" noOfOrder="2"/>
			<mx:Object custId="C5634" custName="Kate" noOfOrder="17"/>
		</mx:Array>
	</mx:ArrayCollection>
<mx:DataGrid dataProvider="{dgProvider}" editable="true" width="550">
		<mx:columns>
			<mx:DataGridColumn dataField="custId" headerText="Customer ID" rendererIsEditor="true" itemRenderer="mx.controls.TextInput"/>
			<mx:DataGridColumn dataField="custName" rendererIsEditor="true" headerText="Customer Name" width="250">
				<mx:itemRenderer>
					<mx:Component>
						<mx:HBox>
							<mx:Script>
							<![CDATA[
								import mx.controls.Alert;
								public function get text():String
								{
									return txtCustName.text;
								}
							]]&gt;
							</mx:Script>
							<mx:TextInput text="{data.custName}" id="txtCustName"/> <mx:Spacer width="15"/>
							<mx:Button click="Alert.show('Display search popup here.')" icon="@Embed('../images/search.gif')" width="15" height="15"/>
						</mx:HBox>
					</mx:Component>
				</mx:itemRenderer>
			</mx:DataGridColumn>
			<mx:DataGridColumn dataField="noOfOrder" headerText="# of Order" rendererIsEditor="true" itemRenderer="mx.controls.TextInput"/>
		</mx:columns>
	</mx:DataGrid>
</mx:Application>
</pre>
<p>Well does that mean, there is no way to achieve perfect tabbing in DataGrid, aha &#8211; thats not true at all. You can certainly tweak Flex framework and achieve the desired functionality by adding few lines of ActionScript and changing the root tag.</p>
<p>Here is the working version of same.</p>
<pre class="brush: xml;">
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:ArrayCollection id="dgProvider">
		<mx:Array>
			<mx:Object custId="C1191" custName="John Michael" noOfOrder="10"/>
			<mx:Object custId="C2252" custName="Ginny" noOfOrder="5"/>
			<mx:Object custId="C3442" custName="Jeremy" noOfOrder="2"/>
			<mx:Object custId="C5634" custName="Kate" noOfOrder="17"/>
		</mx:Array>
	</mx:ArrayCollection>
<mx:DataGrid dataProvider="{dgProvider}" editable="true" width="550">
		<mx:columns>
			<mx:DataGridColumn dataField="custId" headerText="Customer ID" rendererIsEditor="true" itemRenderer="mx.controls.TextInput"/>
			<mx:DataGridColumn dataField="custName" rendererIsEditor="true" headerText="Customer Name" width="250">
				<mx:itemRenderer>
					<mx:Component>
						<mx:UIComponent keyFocusChange="keyFocusChangeHandler(event)" implements="mx.controls.listClasses.IListItemRenderer, mx.managers.IFocusManagerComponent">
							<mx:Script>
							<![CDATA[
								import mx.controls.Alert;
								import mx.controls.listClasses.BaseListData;

								public function get text():String
								{
									return txtCustName.text;
								}

								override public function setFocus():void
								{
									txtCustName.setFocus();
									txtCustName.drawFocus(true);
								}

								private function keyFocusChangeHandler(event:FocusEvent):void
								{
									if (event.shiftKey)
									{
										if (btnSearch.contains(getFocus()))
										{
											event.preventDefault();
											txtCustName.setFocus();
										}
									}else
									{
										if (txtCustName.contains(getFocus()))
										{
											event.preventDefault();
											btnSearch.setFocus();
										}
									}
								}

								private var _data:Object;

								[Bindable]
								public function get data():Object
								{
									return _data;
								}

								public function set data(value:Object):void
								{
									this._data = value;
								}

								private var _listData:BaseListData;

								public function get listData():BaseListData
								{
									return _listData;
								}

								public function set listData(value:BaseListData):void
								{
									_listData = value;
								}

								override protected function createChildren():void
								{
									super.createChildren();
									addChild(hContainer);
								}

								override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
								{
									hContainer.width = unscaledWidth;
									hContainer.height = unscaledHeight;
								}
							]]&gt;
							</mx:Script>
							<mx:HBox id="hContainer">
								<mx:TextInput text="{data.custName}" id="txtCustName"/> <mx:Spacer width="15"/>
								<mx:Button id="btnSearch" click="Alert.show('Display search popup here.')" icon="@Embed('../images/search.gif')" width="15" height="15"/>
							</mx:HBox>
						</mx:UIComponent>
					</mx:Component>
				</mx:itemRenderer>
			</mx:DataGridColumn>
			<mx:DataGridColumn dataField="noOfOrder" headerText="# of Order" rendererIsEditor="true" itemRenderer="mx.controls.TextInput"/>
		</mx:columns>
	</mx:DataGrid>
</mx:Application>
</pre>
<p>You will require serach.gif image in order to run this sample program.</p>
<p>Updated: To download above source code, please <a href="http://www.carbonrider.com/wp-content/uploads/2010/09/datagrid-tabbing-src.zip">click here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://flex.carbonrider.com/2009/12/19/item-editor-tabbing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Spring JMS API, JBoss MQ, BlazeDS &amp; Flex</title>
		<link>http://flex.carbonrider.com/2009/10/03/spring-jms-api-and-jboss-mq/</link>
		<comments>http://flex.carbonrider.com/2009/10/03/spring-jms-api-and-jboss-mq/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 15:34:37 +0000</pubDate>
		<dc:creator>Carbon Rider</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Blaze DS]]></category>
		<category><![CDATA[Flex Chatting]]></category>
		<category><![CDATA[Flex Messaging]]></category>
		<category><![CDATA[JBoss MQ]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring Integration]]></category>

		<guid isPermaLink="false">http://www.carbonrider.com/?p=122</guid>
		<description><![CDATA[This time one more assignment to integrate Spring APIs with Jboss MQ. After reading through Spring documentation, I found its pretty easy to integrate any Messaging Provider solution into Spring application. Configuring JMS Topic in JBoss To create new JMS Topic destination you should configure new topic destination in [deploy_directory]/deploy/jms/jbossmq-destinations-service.xml. Following code snippet creates new [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fflex.carbonrider.com%2F2009%2F10%2F03%2Fspring-jms-api-and-jboss-mq%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fflex.carbonrider.com%2F2009%2F10%2F03%2Fspring-jms-api-and-jboss-mq%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>This time one more assignment to integrate Spring APIs with Jboss MQ. After reading through Spring documentation, I found its pretty easy to integrate any Messaging Provider solution into Spring application.</p>
<p><strong>Configuring JMS Topic in JBoss</strong></p>
<p>To create new JMS Topic destination you should configure new topic destination in [deploy_directory]/deploy/jms/jbossmq-destinations-service.xml. Following code snippet creates new Topic Destination.</p>
<p><span id="more-122"></span></p>
<pre name="code" class="xml">
<mbean code="org.jboss.mq.server.jmx.Topic" name="jboss.mq.destination:service=Topic,name=MyTopic">
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
<depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
<attribute name="SecurityConf">
<security>
<role name="guest" read="true" write="true" create="true"/>
</security>
</attribute>
</mbean>
</pre>
<p>Well in actual production system you should not configure guest role access with Read/write permission. Add above XML code snippet below &lt;server&gt; tag and save it. Start JBoss console and you should notice that JBoss will create new topic and bind it to JNDI with name as &#8220;topic/MyTopic&#8221; (Note this is generic JMS client configuration and doesn&#8217;t use any properitory JMS provider APIs. You will have to change the properties of jndiTemplate based on your Messaging Service Provider.)</p>
<p><strong>Using Spring API</strong></p>
<p>Now lets create client code to send messages. I assume that you are using Spring &#8211; BlazeDs integration project and aware of how to configure Spring configuration file with BlazeDS. The following code snippet must be defined in Spring configuration file. Make sure you have also imported Spring-Flex namespace.</p>
<pre  name="code" class="xml">
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="java.naming.provider.url">localhost</prop>
<prop key="java.naming.factory.url.pkgs"> org.jnp.interfaces:org.jboss.naming </prop>
</props>
</property>
</bean>
</pre>
<pre name="code" class="xml">
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName">
<value>java:/XAConnectionFactory</value>
</property>
</bean>
</pre>
<pre name="code" class="xml">
<bean id="jmsDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate"><ref bean="jndiTemplate"/></property>
<property name="jndiName"><value>topic/MyTopic</value></property>
</bean>
</pre>
<p>Now you can expose jmsDestination using flex:jms-message-destination tag. (Available with Spring-BlazeDS integration jar.)</p>
<pre name="code" class="xml">
<flex:jms-message-destination id="my-topic-jms"  jms-destination="jmsDestination" />
</pre>
<p><strong>Creating Flex Client</strong></p>
<p>We are done with the server side configuration and now its time to define Flex Client to subscribe to JMS topic. Flex comes with a handy tag as MX:Consumer and MX:Producer. MX:Consumer is useful to subscribe to JMS topics and queues, while MX:Producer by the name itself it is quite clear that this tag is used to publish messages to JMS. Declare following tag to subscribe to JMS topic</p>
<pre name="code" class="xml">
<mx:Consumer destination="my-topic-jms" id="messageConsumer" message="consumerMessageHandler(event)" fault="faultHandler(event)"/>
</pre>
<p>Note that in above example the value of destination attribute is exactly same as the value of id attribute defined for jms-message-destination tag. This still won&#8217;t start subscription to JMS topic and in order to start subscription you must explicitly subscribe to JMS topic by calling subscribe method  on MX:Consumer instance. Let assume that following function is invoked on &#8220;CreationComplete&#8221; event of application.</p>
<p>private function subscribeTopic():void<br />
{<br />
messageConsumer.subscribe();<br />
}</p>
<p>This will start subscription to JMS topic destination and keep on polling to message server for any new message. OK! but how you will receive message notification, notice there are two event handler defined with MX:Consumer tag declaration. And here is the code snippet of &#8220;message&#8221; event handler.</p>
<p>private function consumerMessageHandler(event:MessageEvent):void<br />
{</p>
<p>var msg:AsyncMessage = new AsyncMessage(event.message);<br />
Alert.show(ObjectUtil.toString(msg.body));<br />
}</p>
<p>This function just prints all the contents of the Message. If you are accessing Object style JMS message, the properties of such message can be accessed using &#8220;.&#8221; notation.</p>
<p><strong>Deployment</strong></p>
<p>Package all the generated SWFs and copy all the required files (JAR, XML configuration files etc) to a WAR file and deploy it on JBoss server. Hit your application URL and you should be able to receive any messages sent to JMS topic.</p>
<p><strong>Known Issue</strong></p>
<p>At the time of deployment, you might come across following exception being thrown by JBoss</p>
<p>: Failed to convert property value of type [org.jboss.mq.SpyXAConnectionFactory] to required type [javax.jms.ConnectionFactory] for property &#8216;connectionFactory&#8217;</p>
<p>Make sure that the deployed WAR file doesn&#8217;t contain and JMS-API library file. The above error is occurring due to ClassLoader issue but the error message is misleading.</p>
]]></content:encoded>
			<wfw:commentRss>http://flex.carbonrider.com/2009/10/03/spring-jms-api-and-jboss-mq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
