Monday, February 10, 2014

Adobe Flex: JSON.stringify(object) - error

Issue: When JSON.stringify(object) used for an object which contains an attribute of type "ArrayCollection", it throws an error.
Error: Unknown Property: 'dispatchResetEvent'.
 at mx.collections::ListCollectionView/http://www.adobe.com/2006/actionscript/flash/proxy::getProperty()
 at JSON$/stringifySpecializedToString()
 at JSON$/stringify()
Fix: Use Array instead of ArrayCollection.

Wednesday, January 30, 2013

Adobe Flex 4: Indeterminate Progress bar

I used the following code to create a Indeterminate progress bar in a Flex 4 application.

MXML code:


<mx:ProgressBar id="progBar" width="225" 
	mode="manual" label="Loading ..." labelPlacement="center" 
	maximum="0" minimum="0" visible="false" indeterminate="true" 
	includeInLayout="false"
	fontWeight="bold" />

Show/Hide methods:
public function showLoading(event:ApplicationEvent):void
{
	if(progBar) { 
		
		PopUpManager.removePopUp(progBar);
		
		progBar.visible  = true;
		if (event.label && event.label != '') {
			progBar.label = event.label;
		} else {
			progBar.label = 'Loading ...';
		}
		PopUpManager.addPopUp(progBar,this,true);
		PopUpManager.centerPopUp(progBar);
		
		trackTimeTakenForRequest();
	}
}

public function hideLoading(event:ApplicationEvent):void {
	if (progBar) {
		PopUpManager.removePopUp(progBar);
		progBar.visible = false;
	}
	if (minuteTimer.running) {
		minuteTimer.stop();
	}
}

Timer for handling unusually long requests:
// creates a new 10-second Timer				
var minuteTimer:Timer = new Timer(1000, 15);
public function trackTimeTakenForRequest():void {				
	if (minuteTimer.running) {
		minuteTimer.stop();
	}
	minuteTimer.start();
}

public function onTimerComplete(event:TimerEvent):void {
  if(progBar && progBar.visible) {
    progBar.visible = false;
    PopUpManager.removePopUp(progBar);
    showLoading(new ApplicationEvent(ApplicationEvent.SHOW_PROGRESS_BAR, 
"This request is taking longer than usual."))
	}			
}

Tuesday, July 19, 2011

MyEclipse Reports 2.2 - Oracle Stored procedure with OUT parameters

I am using MyEclipse Reports 2.2 for generating PDF reports in my project but was struck with as it does not support the following features out-of-box.
1) Stored procedure Datasets
2) OUT parameters

I sought of worked around this issue by doing the following:

1) Used Eclipse BIRT to create a report(which supports the above features)
2) copied over the Dataset configurations from the BIRT Report XML file to MyEclipse report xml file.
This works like a charm!

Note: Make sure you have appropriate version number in your Report design XML file.

Hope this might save somebody sometime, which would otherwise be spent trying to resolve this issue.

SYBASE SQL for formatting Phone numbers

This sql formats a phone number without using Regular expression.
Steps:
-----
1) check for empty or NULL value.
2) check if size is greater than 10.
a) size > 10, format with extension
b) else, format as a 10 digit phone number

select
case when len(str_replace(phone_no,'',NULL)) = NULL
then ''

when len(str_replace(str_replace(str_replace(str_replace(phone_no,')',''),'(',''), '-', ''),'',NULL)) > 10

then
'('||substring(str_replace(str_replace(str_replace(str_replace(phone_no,')',''),'(',''), '-', ''),'',NULL), 1, 3)
|| ')' || substring(str_replace(str_replace(str_replace(str_replace(phone_no,')',''),'(',''), '-', ''),'',NULL), 4, 3)
|| '-' || substring(str_replace(str_replace(str_replace(str_replace(phone_no,')',''),'(',''), '-', ''),'',NULL), 7, 4)
|| ' ext:' || substring(str_replace(str_replace(str_replace(str_replace(phone_no,')',''),'(',''), '-', ''),'',NULL), 10,5)

else
'('||substring(str_replace(str_replace(str_replace(str_replace(phone_no,')',''),'(',''), '-', ''),'',NULL), 1, 3)
|| ')' || substring(str_replace(str_replace(str_replace(str_replace(phone_no,')',''),'(',''), '-', ''),'',NULL), 4, 3)
|| '-' || substring(str_replace(str_replace(str_replace(str_replace(phone_no,')',''),'(',''), '-', ''),'',NULL), 7,4)
end as PHONE_NO
from person

I have not checked if Sybase supports regular expression, in which case it might be much simpler. Please share if you have a better solution.

Oracle SQL - Formatting zip code

This code will format zip code in the format xxxxx-xxx..., using regular expression.

Steps involved:
1) first removes any non-numeric characters
2) if the lenght is greater than 5 characters, introduces a '-' after first 5 characters.
3) returns the non-numeric zip, otherwise.


select decode(ZIP,NULL,'', CHR(13)
||
case when length(REGEXP_REPLACE(ZIP, '[^0-9]+', '')) > 5
then
REGEXP_REPLACE(REGEXP_REPLACE(ZIP, '[^0-9]+', ''),'(.....)(.*)','\1-\2')
else
REGEXP_REPLACE(ZIP, '[^0-9]+', '')
end
)
from address;

Tuesday, August 24, 2010

Adobe Flex multi stacked bar chart

We had a requirement in our project to show multi stacked bar chart and I found that it is not a out of box component that we can achieve using Flex charting components.
After a little bit of research and learning, I found that this can be done using the following code:



<mx:ColumnChart id="revBySetChart1" showDataTips="true" width="100%"
dataProvider="{dataCollection}"
dataTipFunction="formattingMethod"
height="380" paddingLeft="0">

<mx:verticalAxis>
<mx:LinearAxis title="verticalAxisTitle" labelFunction="defineVerticalLabel" />
</mx:verticalAxis>

<mx:horizontalAxis>
<mx:CategoryAxis id="horizontalCategoryId" categoryField="categoryFieldName" />
</mx:horizontalAxis>

<mx:series>
<chart:ColumnSet type="clustered">
<chart:ColumnSet type="stacked" displayName="displayName1">
<mx:ColumnSeries yField="yfield11" displayName="columndisplayname1" styleName="mySeries1"/>
<mx:ColumnSeries yField="yfield12" displayName="columndisplayname2" styleName="mySeries2"/>
</chart:ColumnSet>
<chart:ColumnSet type="stacked" displayName="displayName2" >
<mx:ColumnSeries yField="yfield21" displayName="columndisplayname1" styleName="mySeries1"/>
<mx:ColumnSeries yField="yfield22" displayName="columndisplayname2" styleName="mySeries2" tabIndex="1"/>
</chart:ColumnSet>
</chart:ColumnSet>
</mx:series>
</mx:ColumnChart>


Here, displayName1 and displayName2 are stacked bars.
These are in turn placed inside a clustered series to achieve the multi stacked bar graph.

In Adobe Flex, a most discussed limitation is that the Datagrid or AdvancedDataGrid components do not support a footer row for showing some aggregate functions.

A popular and simple solution for this is to create a secondary datagrid whose dataProvider is a aggregate collection of the master datagrid data.

But we need to handle certain properties for footer datagrid to achieve this. some of them are :

1) on stretch of the master datagrid columns, we need to change the column width of the footer datagrid also.

eg: we can write a columnStretchHandler and assign this method to the "columnStretch" property of the master datagrid as follows:


private function columnStretchHandler(event:AdvancedDataGridEvent):void {

var dg:AdvancedDataGrid = event.target as AdvancedDataGrid;

<footer_datagrid_id>.columns[event.columnIndex].width =

dg.columns[event.columnIndex].width;

}



2) Other properties that may have to be set are :
rowCount="1"
showHeaders="false"
maxHeight="30"
sortExpertMode="true"
sortableColumns="false"