Flex 3 DataGrid Tab Order - actionscript-3

I've been trying to get the tab order to work on this datagrid for some time now and I can't figure out what I am doing wrong. Can anyone spot it?
<?xml version="1.0" encoding="utf-8"?>
<controls:MDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="com.iwobanas.controls.*"
xmlns:dgc="com.iwobanas.controls.dataGridClasses.*"
dataProvider="{locator.vendorInvoices}">
<mx:Script>
<![CDATA[
import com.model.PayablesLocator;
[Bindable] private var locator:PayablesLocator = PayablesLocator.getInstance();
]]>
</mx:Script>
<controls:columns>
<dgc:MDataGridColumn dataField="loadNumber"
headerText="Load"/>
<dgc:MDataGridColumn dataField="carrierName"
headerText="Carrier"/>
<mx:DataGridColumn dataField="vendorInvoiceNumber"
headerText="Vendor Invoice #"
rendererIsEditor="true"
editorDataField="vendorInvoiceNumber">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Script>
<![CDATA[
protected function invoiceNumberInput_changeHandler(event:Event):void {
data.vendorInvoiceNumber = invoiceNumberInput.text;
}
]]>
</mx:Script>
<mx:TextInput id="invoiceNumberInput"
text="{data.vendorInvoiceNumber}"
editable="true"
width="95%"
change="invoiceNumberInput_changeHandler(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="vendorInvoiceDate"
headerText="Invoice Date"
rendererIsEditor="true"
editorDataField="vendorInvoiceDate">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CalendarLayoutChangeEvent;
import mx.events.CloseEvent;
protected function invoiceDateChanged(event:CalendarLayoutChangeEvent):void {
data.vendorInvoiceDate = event.newDate;
}
]]>
</mx:Script>
<mx:DateField id="vendorInvoiceDateInput"
selectedDate="{data.vendorInvoiceDate}"
editable="true"
width="95%"
change="invoiceDateChanged(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="isSelected"
headerText="Select"
rendererIsEditor="true"
editorDataField="isSelected">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" verticalAlign="middle">
<mx:Script>
<![CDATA[
import com.controller.PayablesController;
private var control:PayablesController = PayablesController.getInstance();
private function onCheckboxClick():void {
data.isSelected = selectionCheckBox.selected;
control.updateBatchSelections();
}
]]>
</mx:Script>
<mx:CheckBox id="selectionCheckBox"
selected="{data.isSelected}"
change="onCheckboxClick()"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</controls:columns>
I'm trying to get the tab order as follows for each row: Vendor Invoice > Invoice Date > Select, but when I try to tab to the next field it jumps to the URL of the browser (IE in this case). I've tried a bunch of things found on the net, but none of them have seemed to work.
Any help would be greatly appreciated.
--Charly

There is no built in support for this. This will work if you have editable cells, and that too it will only work if your editors implement IFocusManagerComponent. (In this case your editors are wrapped inside HBoxes which do not). If you were using the spark datagrid, you could use : http://squaredi.blogspot.com/2011/09/precision-focus-control-within-spark.html

Resulting working code:
<?xml version="1.0" encoding="utf-8"?>
<controls:MDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="com.iwobanas.controls.*"
xmlns:dgc="com.iwobanas.controls.dataGridClasses.*"
dataProvider="{locator.vendorInvoices}"
editable="true">
<mx:Script>
<![CDATA[
import com.model.PayablesLocator;
[Bindable] private var locator:PayablesLocator = PayablesLocator.getInstance();
]]>
</mx:Script>
<controls:columns>
<dgc:MDataGridColumn dataField="loadNumber"
headerText="Load"
editable="false"/>
<dgc:MDataGridColumn dataField="carrierName"
headerText="Carrier"
editable="false"/>
<mx:DataGridColumn dataField="vendorInvoiceNumber"
headerText="Vendor Invoice #"
rendererIsEditor="true"
editorDataField="value">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
[Bindable] public var value:String;
override public function drawFocus(draw:Boolean):void {
invoiceNumberInput.setFocus();
}
]]>
</mx:Script>
<mx:TextInput id="invoiceNumberInput"
text="{value}"
width="95%"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="vendorInvoiceDate"
headerText="Invoice Date"
rendererIsEditor="true"
editorDataField="value">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
[Bindable] public var value:Date;
override public function drawFocus(draw:Boolean):void {
vendorInvoiceDateInput.setFocus();
}
]]>
</mx:Script>
<mx:DateField id="vendorInvoiceDateInput"
selectedDate="{value}"
editable="true"
width="95%"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn editorDataField="isSelected"
headerText="Select"
rendererIsEditor="true">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.controls.listClasses.IDropInListItemRenderer,mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import com.controller.PayablesController;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
private var control:PayablesController = PayablesController.getInstance();
private var _listData:DataGridListData;
[Bindable] public var isSelected:Boolean;
override public function drawFocus(draw:Boolean):void {
selectionCheckBox.setFocus();
}
override public function get data():Object {
return super.data;
}
override public function set data(value:Object):void {
super.data = value;
selectionCheckBox.selected = data.isSelected
}
public function get listData():BaseListData {
return _listData;
}
public function set listData(value:BaseListData):void {
_listData = DataGridListData(value);
}
protected function onChange(event:Event):void {
data.isSelected = selectionCheckBox.selected;
control.updateBatchSelections();
}
]]>
</mx:Script>
<mx:CheckBox id="selectionCheckBox" change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</controls:columns>

Related

Update total value datagrid when drag drop values - Adobe Flex

I have two datagrid, and each has total label. This label sums all the values of each datagrid.
When I drag and drop a value from one datagrid to another, the two label total must be updated according to the values of each datagrid.
However, a sum is delayed.
The code:
<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="650"
creationComplete="initApp();">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.DataGridEvent;
import mx.events.DragEvent;
private function initApp():void {
dgA.dataProvider = new ArrayCollection([
{Expense:'Electricity', Value:300, minNo: 100, maxNo: 500},
{Expense:'Phone', Value:200, minNo: 50, maxNo: 300},
{Expense:'Contract A', Value:5000, minNo: 4000, maxNo: 6000},
{Expense:'Contract B', Value:6000, minNo: 4500, maxNo: 8500},
{Expense:'Contract C', Value:3000, minNo: 2500, maxNo: 3500}
]);
dgB.dataProvider = new ArrayCollection([]);
sumA();
}
private function disableEditing(event:DataGridEvent):void {
if(event.columnIndex==0)
{
event.preventDefault();
}
}
public function sumA():void {
var sum:Number = 0;
for (var k:String in dgA.dataProvider){
sum += dgA.dataProvider[k]['Value'];
}
totalA.text = sum.toString();
}
public function sumB():void {
var sum:Number = 0;
for (var k:String in dgB.dataProvider){
sum += dgB.dataProvider[k]['Value'];
}
totalB.text = sum.toString();
}
public function dragDropHandler(event:DragEvent):void {
sumA();
sumB();
}
]]>
</fx:Script>
<s:HGroup>
<s:VGroup>
<s:Label text="Cost 1"/>
<mx:DataGrid id="dgA"
allowMultipleSelection="true"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
dragDrop="dragDropHandler(event)">
<mx:columns>
<mx:DataGridColumn dataField="Expense"/>
<mx:DataGridColumn dataField="Value"/>
</mx:columns>
</mx:DataGrid>
<s:Form>
<s:FormItem label="Total">
<s:Label id="totalA"/>
</s:FormItem>
</s:Form>
</s:VGroup>
<s:VGroup>
<s:Label text="Cost 2"/>
<mx:DataGrid id="dgB"
allowMultipleSelection="true"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
editable="true"
itemEditBeginning="disableEditing(event);"
dragDrop="dragDropHandler(event)">
<mx:columns>
<mx:DataGridColumn dataField="Expense"/>
<mx:DataGridColumn dataField="Value" editorDataField="value">
<mx:itemEditor>
<fx:Component>
<mx:NumericStepper stepSize="1" width="35" height="20">
<fx:Script>
<![CDATA[
override public function set data(value:Object):void
{
super.data = value;
if (value && value.hasOwnProperty("minNo")) {
minimum = value.minNo;
}
if (value && value.hasOwnProperty("maxNo")) {
maximum = value.maxNo;
}
}
]]>
</fx:Script>
</mx:NumericStepper>
</fx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<s:Form>
<s:FormItem label="Total">
<s:Label id="totalB"/>
</s:FormItem>
</s:Form>
</s:VGroup>
</s:HGroup>
</s:Application>
Use callLater() method to call the sum method from dragDropHandler as below
public function dragDropHandler(event:DragEvent):void {
callLater(doTotal);
}
public function doTotal():void{
sumA();
sumB();
}
I tested it and it is working fine for me.

DataGrid Image ItemRenderer --> How to change image source of other rows, not only the selected one

I have an Image in my DataGrid. Its purpose is to play and stop an audio, so I need to change the image source from the "Play" image to the "Stop" image every time I click on it.
I've already accomplished that with the next code:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="Audio List"
horizontalScrollPolicy="off" verticalScrollPolicy="auto"
showCloseButton="true" close="closeWindow()">
<mx:Script>
<![CDATA[
import flash.external.ExternalInterface;
import mx.collections.ArrayCollection;
import mx.managers.PopUpManager;
public var dpc:ArrayCollection;
private function closeWindow(){
PopUpManager.removePopUp(this);
ExternalInterface.call("pauseAudio");
}
]]>
</mx:Script>
<mx:Rotate id="rotate" />
<mx:Zoom id="zoom" />
<mx:VBox width="100%" top="20">
<mx:Text fontWeight="bold" top="20" left="20">
<mx:text>Click the play/pause button for listening/pause each audio individually:</mx:text>
</mx:Text>
<mx:DataGrid id="gridAudios" top="60" bottom="0" left="0" width="100%" height="100%" doubleClickEnabled="true">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="audioId"/>
<mx:DataGridColumn id="btnCol" dataField="url" headerText="" textAlign="center">
<mx:itemRenderer>
<mx:Component>
<mx:HBox>
<mx:Image click="changeImg(data.url)" toolTip="Play"
id="imgPlayStop" useHandCursor="true"/>
<mx:Script>
<![CDATA[
import mx.states.State;
import mx.collections.ArrayCollection;
[Embed(source='../assets/play-btn-small.png')]
[Bindable]
public var Play:Class;
[Embed(source='../assets/stop-btn-small.png')]
[Bindable]
public var Stop:Class;
private function init():void
{
imgPlayStop.source = Play
var statePlaying:State = new State();
var stateStopped:State = new State();
statePlaying.name="playing";
stateStopped.name="stopped";
var states:Array = new Array();
states.push(statePlaying);
states.push(stateStopped);
imgPlayStop.states = states;
imgPlayStop.currentState = "stopped";
}
private function changeImg(url:String):void{
if (imgPlayStop.currentState == "stopped"){
imgPlayStop.source = Stop;
imgPlayStop.currentState = "playing";
ExternalInterface.call("playAudio", url);
} else {
imgPlayStop.source = Play;
imgPlayStop.currentState = "stopped";
ExternalInterface.call("pauseAudio");
}
}
]]>
</mx:Script>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
</mx:TitleWindow>
But the thing is that I want to change the image source of the other rows of the DataGridColumn.
For example, if I click in the play image of one row it changes to the stop image, everything OK till here.
If now I click the play image of other row, it also changes to the stop image, but the previous row still remains with the stop image, and I want to be only one stope image active.
In other words, I want to give the impression only one audio is playing. So only one of the rows can be with the "Stop" image while the rest must be with the "Play" image.
So, ¿how can I loop through the DataGridColumn items renderer and change their image source every time I click in on of the items renderer?
You can save prev imgPlayStop as public static variable in a Model class and use it
public class Model {
public static var prevImgPlayStop:Image;
}
in your itemRenderer do like this
private function changeImg(url:String):void{
if (Model.prevImgPlayStop) {
Model.prevImgPlayStop.currentState = "stopped";
}
/*your code*/
Model.prevImgPlayStop = imgPlayStop;
}
I post the SOLUTION I founded to my problem:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="Audio List"
horizontalScrollPolicy="off" verticalScrollPolicy="auto" width="510" height="340"
showCloseButton="true" close="closeWindow()">
<mx:Script>
<![CDATA[
import flash.external.ExternalInterface;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
import mx.controls.Alert;
[Embed(source='../assets/play-btn-small.png')]
var Play:Class;
[Embed(source='../assets/stop-btn-small.png')]
var Stop:Class;
[Blindable]
public var dpc:ArrayCollection;
private function titlewindow1_initializeHandler(event)
{
ExternalInterface.addCallback('onFinishAudio', onFinishAudio);
ExternalInterface.addCallback('onStartAudio', onStartAudio);
}
private function closeWindow(){
PopUpManager.removePopUp(this);
ExternalInterface.call("pauseAudio");
}
private function onFinishAudio(audioId:String) {
for ( var audio:Object in dpc )
{
if (audio.audioId == audioId){
audio.status = 'stopped';
}
}
gridAudios.dataProvider = dpc;
dpc.refresh();
}
private function onStartAudio(audioId:String)
{
for ( var audio:Object in dpc )
{
if (audio.audioId != audioId)
{
if (audio.status == 'playing')
{
audio.status='stopped';
}
} else {
//Alert.show("Dgsg","Error");
audio.status='playing';
}
}
gridAudios.dataProvider = dpc;
dpc.refresh();
}
public function playAudio(audioURL:String, audioId:String){
ExternalInterface.call("playAudio", audioURL, id);
}
public function pauseAudio(){
ExternalInterface.call("pauseAudio");
}
]]>
</mx:Script>
<mx:Rotate id="rotate" />
<mx:Zoom id="zoom" />
<mx:VBox top="0" bottom="0" left="0" right="0" paddingTop="20" paddingLeft="20">
<mx:Text fontWeight="bold" height="20">
<mx:text>Click the play/pause button for listening/pause each audio individually:</mx:text>
</mx:Text>
</mx:VBox>
<mx:DataGrid id="gridAudios" top="50" bottom="20" left="20" right="20" width="100%" doubleClickEnabled="false">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="audioId"/>
<mx:DataGridColumn id="btnCol" headerText="" textAlign="center">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center">
<mx:Script>
<![CDATA[
protected function image1_clickHandler(event:MouseEvent):void
{
if (data.status=='playing'){
outerDocument.pauseAudio();
data.status='';
}else{
outerDocument.playAudio(data.url,data.audioId);
data.status='playing';
}
}
]]>
</mx:Script>
<mx:Image click="image1_clickHandler(event)"
toolTip="{data.status=='playing' ? 'Stop' : 'Play'}"
useHandCursor="true" source="{data.status=='playing' ? outerDocument.Stop : outerDocument.Play}"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:TitleWindow>
Where the key to the solution is in the source property of the Image object and in the click handler.

Update to the database - FLEX

I am working with a payment tracking mobile app in Flash Builder 4.6. I am using Flex data management system. I have few issues which are addressed as below:
When I add a contact and click save button, the new contact will be update instantly in the database. The "Add" "Delete" "Read" work well, only when comes to "Update", it just won't work. I clicked on the save button, there is no response - no error code at all.
The code (AddEditView)
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:valueObjects="valueObjects.*"
xmlns:studentsservice="services.studentsservice.*"
title="Add Student" add="view1_addHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
protected function saveBtn_clickHandler(event:MouseEvent):void
{
if (currentState=="Add"){
var students:Students = new Students();
students.firstname = firstnameTextInput.text;
students.lastname = lastnameTextInput.text;
students.cellphone = cellphoneTextInput.text;
students.email = emailTextInput.text;
students.address = addressTextInput.text;
students.class_id = parseInt(classidTextInput.text);
students.photofile = photofileTextInput.text;
createStudentsResult.token = studentsService.createStudents(students);
studentsService.commit();
} else {
/* updateStudentsResult.token = studentsService.updateStudents(students);
studentsService.getDataManager(studentsService.DATA_MANAGER_STUDENTS).autoCommit=false; */
/* students.firstname = firstnameTextInput.text;
students.lastname = lastnameTextInput.text;
students.cellphone = cellphoneTextInput.text;
students.email = emailTextInput.text;
students.address = addressTextInput.text;
students.class_id = parseInt(classidTextInput.text);
students.photofile = photofileTextInput.text; */
updateStudentsResult.token = studentsService.updateStudents(students);
/* studentsService.getDataManager(studentsService.DATA_MANAGER_STUDENTS).autoCommit=false */;
}
}
protected function createStudentsResult_resultHandler(event:ResultEvent):void
{
navigator.replaceView(StudentDetail,event.result as int);
}
protected function cancelBtn_clickHandler(event:MouseEvent):void
{
navigator.popView();
studentsService.commit();
}
protected function view1_addHandler(event:FlexEvent):void
{
if(data == null){
currentState ="Add";
} else {
currentState ="Edit";
students = data as Students;
title ="Edit Student";
}
}
protected function updateStudentsResult_resultHandler(event:ResultEvent):void
{
navigator.popView();
}
]]>
</fx:Script>
<s:states>
<s:State name="Add"/>
<s:State name="Edit"/>
</s:states>
<fx:Declarations>
<valueObjects:Students id="students"/>
<s:CallResponder id="createStudentsResult" result="createStudentsResult_resultHandler(event)"/>
<studentsservice:StudentsService id="studentsService"/>
<s:CallResponder id="updateStudentsResult" result="updateStudentsResult_resultHandler(event)"/>
</fx:Declarations>
<s:actionContent>
<s:Button id="cancelBtn" label="Cancel" click="cancelBtn_clickHandler(event)"/>
<s:Button id="saveBtn" label="Save" click="saveBtn_clickHandler(event)"/>
</s:actionContent>
<s:Scroller left="0" right="0" top="0" bottom="0">
<s:VGroup width="100%" paddingLeft="10" paddingRight="10">
<s:Label paddingTop="15" text="First Name"/>
<s:TextInput id="firstnameTextInput" width="100%" text="#{students.firstname}"/>
<s:Label paddingTop="15" text="Last Name"/>
<s:TextInput id="lastnameTextInput" width="100%" text="#{students.lastname}"/>
<s:Label paddingTop="15" text="Cellphone"/>
<s:TextInput id="cellphoneTextInput" width="100%" text="#{students.cellphone}"/>
<s:Label paddingTop="15" text="Email"/>
<s:TextInput id="emailTextInput" width="100%" text="#{students.email}"/>
<s:Label paddingTop="15" text="Address"/>
<s:TextInput id="addressTextInput" width="100%" text="#{students.address}"/>
<s:Label paddingTop="15" text="Class ID"/>
<s:TextInput id="classidTextInput" width="100%" text="{students.class_id}"/>
<s:Label paddingTop="15" text="Photo file"/>
<s:TextInput id="photofileTextInput" width="100%" text="#{students.photofile}"/>
</s:VGroup>
</s:Scroller>
</s:View>
The code (StudentView)
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:valueObjects="valueObjects.*"
xmlns:studentsservice="services.studentsservice.*"
title="Add Student" add="view1_addHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
protected function saveBtn_clickHandler(event:MouseEvent):void
{
if (currentState=="Add"){
var students:Students = new Students();
students.firstname = firstnameTextInput.text;
students.lastname = lastnameTextInput.text;
students.cellphone = cellphoneTextInput.text;
students.email = emailTextInput.text;
students.address = addressTextInput.text;
students.class_id = parseInt(classidTextInput.text);
students.photofile = photofileTextInput.text;
createStudentsResult.token = studentsService.createStudents(students);
studentsService.commit();
} else {
updateStudentsResult.token = studentsService.updateStudents(students);
}
}
protected function createStudentsResult_resultHandler(event:ResultEvent):void
{
navigator.replaceView(StudentDetail,event.result as int);
}
protected function cancelBtn_clickHandler(event:MouseEvent):void
{
navigator.popView();
studentsService.commit();
}
protected function view1_addHandler(event:FlexEvent):void
{
if(data == null){
currentState ="Add";
} else {
currentState ="Edit";
students = data as Students;
title ="Edit Student";
}
}
protected function updateStudentsResult_resultHandler(event:ResultEvent):void
{
navigator.popView();
}
]]>
</fx:Script>
<s:states>
<s:State name="Add"/>
<s:State name="Edit"/>
</s:states>
<fx:Declarations>
<valueObjects:Students id="students"/>
<s:CallResponder id="createStudentsResult" result="createStudentsResult_resultHandler(event)"/>
<studentsservice:StudentsService id="studentsService"/>
<s:CallResponder id="updateStudentsResult" result="updateStudentsResult_resultHandler(event)"/>
</fx:Declarations>
<s:actionContent>
<s:Button id="cancelBtn" label="Cancel" click="cancelBtn_clickHandler(event)"/>
<s:Button id="saveBtn" label="Save" click="saveBtn_clickHandler(event)"/>
</s:actionContent>
<s:Scroller left="0" right="0" top="0" bottom="0">
<s:VGroup width="100%" paddingLeft="10" paddingRight="10">
<s:Label paddingTop="15" text="First Name"/>
<s:TextInput id="firstnameTextInput" width="100%" text="#{students.firstname}"/>
<s:Label paddingTop="15" text="Last Name"/>
<s:TextInput id="lastnameTextInput" width="100%" text="#{students.lastname}"/>
<s:Label paddingTop="15" text="Cellphone"/>
<s:TextInput id="cellphoneTextInput" width="100%" text="#{students.cellphone}"/>
<s:Label paddingTop="15" text="Email"/>
<s:TextInput id="emailTextInput" width="100%" text="#{students.email}"/>
<s:Label paddingTop="15" text="Address"/>
<s:TextInput id="addressTextInput" width="100%" text="#{students.address}"/>
<s:Label paddingTop="15" text="Class ID"/>
<s:TextInput id="classidTextInput" width="100%" text="{students.class_id}"/>
<s:Label paddingTop="15" text="Photo file"/>
<s:TextInput id="photofileTextInput" width="100%" text="#{students.photofile}"/>
</s:VGroup>
</s:Scroller>
</s:View>
If someone has ever solved similar problem like this, please guide me thru this. Thank you in advance.
My suspision studentsService.commit(); is saving the data into the DB, if the currentState='edit' this code is unreachable. so, in the else block also you have to do a studentsService.commit();
Do you try adding listeners on your service object (RemoteObject) for "invoke", "result", or "fault" to find out what was happening?
I think the request didn't send as you wish. Check out the FaultEvent for more details.

How to populate the combobox with the header Text of the datagrid dynamically in flex 4?

I have a button "get data" on clicking which my data grid gets populated. I want to populate the combobox at the same time with the column name of the data grid. On generating call, the result are getting stored in the last result, whihc then i am storing to the array .
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.events.ListEvent;
import mx.rpc.events.ResultEvent;
import services.ServiceManager;
import spark.events.IndexChangeEvent;
[Bindable] public var ArrColl_selectOptionComboBox:ArrayCollection = new ArrayCollection;
[Bindable] public var SelectOption:ArrayCollection = new ArrayCollection;
[Bindable] public var mainArrColl:ArrayCollection = new ArrayCollection;
[Bindable] public var DGDataProvider:ArrayCollection = new ArrayCollection;
[Bindable] public var DGDataProvider1:ArrayCollection = new ArrayCollection;
public function clear():void
{
DGDataProvider = new ArrayCollection;
}
//clicking on the Get Data button to retrieve from the Jiraissue
protected function button_clickHandler(event:MouseEvent):void
{
getAllJiraissueResult2.token=jiraissueService1.getAllJiraissue();
}
protected function getAllJiraissueResult2_resultHandler(event:ResultEvent):void
{
mainArrColl = getAllJiraissueResult2.lastResult as ArrayCollection;
DGDataProvider = mainArrColl;
}
//protected function Combobox_Option_changeHandler(event:ListEvent):void
//{
//myLabel.text = "You selected: " + ComboBox(event.target).selectedItem.label;
//Value.prompt="Select Value";
//Value.selectedIndex=-1; // reset so prompt shows
//}
]]>
</fx:Script>
<fx:Declarations>
<jiraissueservice1:JiraissueService1 id="jiraissueService1" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
<s:CallResponder id="getAllJiraissueResult2" result="getAllJiraissueResult2_resultHandler(event)"/>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button x="59" y="49" label="GET DATA" id="button" click="button_clickHandler(event)"/>
<mx:DataGrid x="60" y="299" width="800" id="dataGrid" dataProvider="{DGDataProvider}">
<mx:columns>
<mx:DataGridColumn headerText="pkey" dataField="pkey"/>
<mx:DataGridColumn headerText="PROJECT" dataField="pname"/>
<mx:DataGridColumn headerText="CREATED" dataField="CREATED"/>
<mx:DataGridColumn headerText="defectType" dataField="stringvalue"/>
<mx:DataGridColumn headerText="Reporter" dataField="REPORTER"/>
<mx:DataGridColumn headerText="ASSIGNEE" dataField="ASSIGNEE"/>
<mx:DataGridColumn headerText="SLA" dataField="SLA"/>
</mx:columns>
</mx:DataGrid>
<s:Button x="214" y="49" label="RESET" click="clear()"/>
<s:Button x="557" y="168" label="Button"/>
<mx:ComboBox id="Combobox_Option" width="201" dataProvider="{SelectOption}" labelField="label"
prompt="Select Option"
x="59" y="169"/>
<mx:ComboBox id="Value" width="201" labelField="label"
prompt="Select Value" dataProvider="{DGDataProvider1}"
x="308" y="169"/>
<s:Label id="myLabel" text="You selected:" fontWeight="bold" x="59" y="275"/>
If I have understood your question correctly you just want to populate your combobox with datagrid's column names after getting the data. If it is so you can use "columns" property of your grid as dataprovider of the combobox. The "labelField" property should be set to "headerText". After clearing the grid you set the dataprovider of the cb to null.
Here is a simple code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
[Bindable]private var dp:ArrayCollection = new ArrayCollection([
{artist:"Pavement", album:"Slanted and Enchanted", year:"2010", price:39.1},
{artist:"ABBA", album:"Ring Ring", year:"1973", price:45.2},
{artist:"The Betles", album:"Please Please Me", year:"1963", price:29.1}]);
private function onBtnLoad():void
{
myGrid.dataProvider = dp;
cbCategories.dataProvider = myGrid.columns;
cbCategories.labelField = "headerText";
}
private function onBtnReset():void
{
myGrid.dataProvider = null;
cbCategories.selectedIndex = -1;
cbCategories.dataProvider = null;
}
]]>
</fx:Script>
<s:VGroup x="70" y="50">
<s:DataGrid id="myGrid" width="420" height="100" >
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="artist" headerText="Artist's name" width="150"/>
<s:GridColumn dataField="album" headerText="Album"/>
<s:GridColumn dataField="year" headerText="Year" width="50"/>
<s:GridColumn dataField="price" headerText="Price" width="50"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:HGroup>
<s:Button id="btnLoad" label="Load Data" click="onBtnLoad()"/>
<s:Button id="btnReset" label="Reset" click="onBtnReset()"/>
</s:HGroup>
<s:HGroup verticalAlign="bottom">
<s:Label text="Categories:" width="70"/>
<s:ComboBox id="cbCategories"/>
</s:HGroup>
</s:VGroup>
</s:Application>

Flex 3 DataGrid Component Losing Focus

I'm running into problems getting the focus to work on my custom datagrid. It is a subclass of MDataGrid which can be found here.
My problems is, that every other mouse click on inline components actually focuses on the component. The other clicks seem to automatically lose focus to something else, and I can't seem to figure out what is going on. Any help would be greatly appreciated.
Thanks for your time.
--Charly
<?xml version="1.0" encoding="utf-8"?>
<controls:MDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="com.iwobanas.controls.*"
xmlns:dgc="com.iwobanas.controls.dataGridClasses.*"
dataProvider="{locator.vendorInvoices}"
editable="true">
<mx:Script>
<![CDATA[
import model.PayablesLocator;
[Bindable] private var locator:PayablesLocator = PayablesLocator.getInstance();
]]>
</mx:Script>
<controls:columns>
<dgc:MDataGridColumn dataField="loadNumber"
headerText="Load"
editable="false"/>
<dgc:MDataGridColumn dataField="carrierName"
headerText="Carrier"
editable="false"/>
<mx:DataGridColumn headerText="Vendor Invoice #"
rendererIsEditor="true"
editorDataField="vendorInvoiceNumber">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.controls.listClasses.IDropInListItemRenderer, mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.events.FlexEvent;
private var _listData:DataGridListData;
[Bindable] public var vendorInvoiceNumber:String;
// Implements mx.managers.IFocusManagerComponent
override public function drawFocus(draw:Boolean):void {
invoiceNumberInput.setFocus();
}
// Implements mx.controls.listClasses.IDropInListItemRenderer
override public function get data():Object {
return super.data;
}
override public function set data(value:Object):void {
super.data = value;
invoiceNumberInput.text = data.vendorInvoiceNumber
}
public function get listData():BaseListData {
return _listData;
}
public function set listData(value:BaseListData):void {
_listData = DataGridListData(value);
}
private function onChange(event:Event):void {
data.vendorInvoiceNumber = invoiceNumberInput.text;
}
]]>
</mx:Script>
<mx:TextInput id="invoiceNumberInput"
width="95%"
change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Vendor Invoice Date"
rendererIsEditor="true"
editorDataField="vendorInvoiceDate">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import mx.events.CalendarLayoutChangeEvent;
[Bindable] public var vendorInvoiceDate:Date;
// Implements mx.managers.IFocusManagerComponent
override public function drawFocus(draw:Boolean):void {
vendorInvoiceDateInput.setFocus();
}
protected function onChange(event:CalendarLayoutChangeEvent):void {
data.vendorInvoiceDate = event.newDate;
}
]]>
</mx:Script>
<mx:DateField id="vendorInvoiceDateInput"
width="95%"
editable="true"
change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn editorDataField="isSelected"
headerText="Select"
rendererIsEditor="true">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.controls.listClasses.IDropInListItemRenderer,mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import controller.PayablesController;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
private var control:PayablesController = PayablesController.getInstance();
private var _listData:DataGridListData;
[Bindable] public var isSelected:Boolean;
override public function drawFocus(draw:Boolean):void {
selectionCheckBox.setFocus();
}
override public function get data():Object {
return super.data;
}
override public function set data(value:Object):void {
super.data = value;
selectionCheckBox.selected = data.isSelected
}
public function get listData():BaseListData {
return _listData;
}
public function set listData(value:BaseListData):void {
_listData = DataGridListData(value);
}
protected function onChange(event:Event):void {
data.isSelected = selectionCheckBox.selected;
control.updateBatchSelections();
}
]]>
</mx:Script>
<mx:CheckBox id="selectionCheckBox" change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</controls:columns>