[flexcoders] int not serializing properly from Java to ActionScript
I'm properly retrieving a result set from my database, but the serialization from Java to ActionScript screws up my id field along the way. -- My Java VO: public class TestVO { private int id; private String data; public TestVO() { } public TestVO(int id, String data) { this.id = id; this.data = data; } public getID() { return id; } public setID(int id) { this.id = id; } public getData() { return data; } public setData(String data) { this.data = data; } } --- My ActionScript VO: public class TestVO { public var id:int; public var data:String; } ActionScript outputting the data (the ArrayCollection of my TestVO's are bound to a list with the following renderer: ?xml version=1.0 encoding=utf-8? mx:HBox xmlns:mx=http://www.adobe.com/2006/mxml; mx:Script ![CDATA[ import mx.events.FlexEvent; import test.vo.TestVO; private var vo:TestVO; [Bindable] private var str:String; override public function set data(val:Object):void { if(val != null) { super.data = val; vo = val as TestVO; str = vo.id + + vo.data; } dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE)); } ]] /mx:Script mx:Label text={str} / /mx:HBox When displaying the data in a list I see data field properly, but every id displays as 0 in Flex. I've output the records on a JSP page which uses the same DAO, and the records output properly, so I know it's getting out of the database properly. Any suggestions?
[flexcoders] Re: int not serializing properly from Java to ActionScript
Ah, didn't realize that was case-sensitive. The getId and setId change did the trick, thanks a lot. --- In flexcoders@yahoogroups.com, lepusmars [EMAIL PROTECTED] wrote: Try changing getID to getId and setID to setId. --- In flexcoders@yahoogroups.com, ytseshred ytseshred@ wrote: I'm properly retrieving a result set from my database, but the serialization from Java to ActionScript screws up my id field along the way. -- My Java VO: public class TestVO { private int id; private String data; public TestVO() { } public TestVO(int id, String data) { this.id = id; this.data = data; } public getID() { return id; } public setID(int id) { this.id = id; } public getData() { return data; } public setData(String data) { this.data = data; } } --- My ActionScript VO: public class TestVO { public var id:int; public var data:String; } ActionScript outputting the data (the ArrayCollection of my TestVO's are bound to a list with the following renderer: ?xml version=1.0 encoding=utf-8? mx:HBox xmlns:mx=http://www.adobe.com/2006/mxml; mx:Script ![CDATA[ import mx.events.FlexEvent; import test.vo.TestVO; private var vo:TestVO; [Bindable] private var str:String; override public function set data(val:Object):void { if(val != null) { super.data = val; vo = val as TestVO; str = vo.id + + vo.data; } dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE)); } ]] /mx:Script mx:Label text={str} / /mx:HBox When displaying the data in a list I see data field properly, but every id displays as 0 in Flex. I've output the records on a JSP page which uses the same DAO, and the records output properly, so I know it's getting out of the database properly. Any suggestions?
[flexcoders] Re: Actual location of UIComponent
If you have a references to the panel and the component: var pnl:Panel; var cmp:UIComponent; import flash.geom.Point; var pnt:Point = pnl.localToGlobal(new Point(cmp.x, cmp.y)); pnt.x and pnt.y will contain the global coordinates of the UIComponent. Is that what you're looking for? --- In flexcoders@yahoogroups.com, Bhuvan Gupta [EMAIL PROTECTED] wrote: Hi All, How can I find the coordinates/location of a component at runtime when the component is inside a container like Panel and has been rendered as per parent's layout. Thanks
[flexcoders] Trouble Converting java List to ArrayCollection
I'm using RemoteObjects to connect to my backend. In one of my calls I'm trying to return a List of VO's I create after hitting my database. On the Flex side, my result event is firing properly, but when I try to convert the result to an ArrayCollection, instead of getting a proper ArrayCollection I get single element that displays the following when I output it in an alert: obj is: '[object TestVO], [object TestVO], ... [object TestVO]'. If I return a single TestVO object directly instead of a List, I can properly cast the result to my ActionScript TestVO object and view the data properly. It's just returning the List that's giving me problems. Can anyone offer any suggestions please? My Flex result code is: public function result(evt:Object):void { if(evt.type evt.type == ResultEvent.RESULT) { var re:ResultEvent = evt as ResultEvent; var col:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(re.result)); if(col) { Alert.show(obj is: ' + col.getItemAt(0) + '); } else Alert.show(Didn't cast properly!); } } My Java DAO code that returns the list is: public List getList() throws DAOException { List list = new ArrayList(); Connection c = null; try { c = ConnectionHelper.getConnection(); Statement s = c.createStatement(); ResultSet rs = s.executeQuery(SELECT * FROM test); while(rs.next()) { TestVO vo = new TestVO(); vo.id = rs.getInt(id); vo.data = rs.getString(data); list.add(vo); } } catch(Exception e) { e.printStackTrace(); throw new DAOException(e); } finally { ConnectionHelper.close(c); } return list; }
[flexcoders] Re: Using data in an Array Collection
You need to return retString; at the end of the function. --- In flexcoders@yahoogroups.com, jryano001 [EMAIL PROTECTED] wrote: Thanks for the response. This is more than likely me being daft but I've used the code you provided and set the labelFunction of checkData on the status DataGridColumn and I get an error in Flex stating: 1170: Function does not return a value. Is the checkData function checking both my customer and status columns for '2' or do I have to (as I expect) enter in the column name I want to check in the code you provided? I appreciate your help and patience! --- In flexcoders@yahoogroups.com, Clint Tredway grumpee@ wrote: use a labelFunction to check the value and then do something: private function checkData(item:Object,column:Object):String{ var retString:String; if(item['column'] == 2){ retString=Return String; } else { retString = Alt Return string; } } then set this as the labelFunction on that DataGridColumn and that should get you going. On 2/12/07, jryano001 jryan@ wrote: Hi, I'm very new to Flex and hope someone advise me on this or tell me if it's even possible! My Flex application is pulling data using a php page. The data is then parsed into XML and is placed inside an ArrayCollection called custData. My DataGrid is then using custData as it's dataProvider. This is all working and my Datarid displays my two colmuns (cust status). What I need to be able to do though is to check the values in my status column and if any of these change to '2' then trigger an event (at the moment this could just be to display some text). I know (unless someone tells me otherwise) that I need an If statement to check the values of status in my ArrayCollection but I need to know how you access just the values of status and if one has changed to '2' then to display the text. I'd really appreciate if someone could point me in the right direction. Thanks in advance. If it makes anything clearer then my code is below. -- ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; initialize=custRequest.send() mx:Script ![CDATA[ import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; [Bindable] private var custData:ArrayCollection; private function resultHandler (event:ResultEvent):void { custData = event.result.cstatus.customer; } ]] /mx:Script mx:HTTPService id=custRequest url=http://localhost/FlexTest/retrieve.php; result=resultHandler(event)/ mx:DataGrid dataProvider={custData} mx:columns mx:DataGridColumn headerText=Customer dataField=cust/ mx:DataGridColumn headerText=Status dataField=status/ /mx:columns /mx:DataGrid /mx:Application -- http://indeegrumpee.spaces.live.com/
[flexcoders] Re: Trouble Converting java List to ArrayCollection
Thanks, the casting directly to ArrayCollection using as did work. I was doing this initially, and then made some other changes to get rid of another error and forgot to change back. Andre, this isn't production code and I got it off of Cristophe's TestDriver server (http://coenraets.org/blog/2007/01/flex-data-management-services-tutorial/) but thanks for pointing this out. --- In flexcoders@yahoogroups.com, André Rodrigues Pena [EMAIL PROTECTED] wrote: Man.. Just remove the throws of your getList() method. Never use throws at a service method. (specially in this example where the throws is USELESS because you are already treating the exception with the try clause) The throws clause passes the exception treatment to a higher scope, this scope may not import de DAOException needed to process it properly. Simply never do this. On 2/12/07, ytseshred [EMAIL PROTECTED] wrote: I'm using RemoteObjects to connect to my backend. In one of my calls I'm trying to return a List of VO's I create after hitting my database. On the Flex side, my result event is firing properly, but when I try to convert the result to an ArrayCollection, instead of getting a proper ArrayCollection I get single element that displays the following when I output it in an alert: obj is: '[object TestVO], [object TestVO], ... [object TestVO]'. If I return a single TestVO object directly instead of a List, I can properly cast the result to my ActionScript TestVO object and view the data properly. It's just returning the List that's giving me problems. Can anyone offer any suggestions please? My Flex result code is: public function result(evt:Object):void { if(evt.type evt.type == ResultEvent.RESULT) { var re:ResultEvent = evt as ResultEvent; var col:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(re.result)); if(col) { Alert.show(obj is: ' + col.getItemAt(0) + '); } else Alert.show(Didn't cast properly!); } } My Java DAO code that returns the list is: public List getList() throws DAOException { List list = new ArrayList(); Connection c = null; try { c = ConnectionHelper.getConnection(); Statement s = c.createStatement(); ResultSet rs = s.executeQuery(SELECT * FROM test); while(rs.next()) { TestVO vo = new TestVO(); vo.id = rs.getInt(id); vo.data = rs.getString(data); list.add(vo); } } catch(Exception e) { e.printStackTrace(); throw new DAOException(e); } finally { ConnectionHelper.close(c); } return list; } -- André Rodrigues Pena LOCUS www.locus.com.br Blog www.techbreak.org
[flexcoders] Re: Trouble Converting java List to ArrayCollection
That was a typo on my Part. They are being set using methods: TestVO vo = new TestVO(); vo.setID(rs.getInt(id)); vo.setData(rs.getString(data)); The problem has been solved by casting the result to ArrayCollection using the as keyword. I'm not sure what was causing my first problem, but I originally had my VO's defined with constructors, so I could create the VO like: TestVO vo = new TestVO(rs.getInt(id), rs.getString(data)); But Flex gave a runtime error when it was constructing the array collection saying something like TestVO init expected 2 arguments and got 0. --- In flexcoders@yahoogroups.com, lepusmars [EMAIL PROTECTED] wrote: I have to disagree about not throwing the Exception. If you actually handle the exception in the method then you shouldn't throw it, but the exception is not being handled. The user needs to know that something went wrong. And the bit about the Higher scope not importing the DAOException, that's just plain wrong. The higher scope will see it as an Exception if it doesn't handle the specific Exception. Not throwing the exception will simply return an empty list. The real question is what is the Exception that is being thrown in the try block? That will tell us what the issue is and lead us to the conclusion as to how to fix it. Is there a Stack Trace available that I can look at? Also... vo.id = rs.getInt(id); vo.data = rs.getString(data); ... this is bad from. You shouldn't be accessing data members directly, they should be encapsulated, and you should access them using accesser methods. Paul --- In flexcoders@yahoogroups.com, André Rodrigues Pena andre.ufrj@ wrote: Man.. Just remove the throws of your getList() method. Never use throws at a service method. (specially in this example where the throws is USELESS because you are already treating the exception with the try clause) The throws clause passes the exception treatment to a higher scope, this scope may not import de DAOException needed to process it properly. Simply never do this. On 2/12/07, ytseshred ytseshred@ wrote: I'm using RemoteObjects to connect to my backend. In one of my calls I'm trying to return a List of VO's I create after hitting my database. On the Flex side, my result event is firing properly, but when I try to convert the result to an ArrayCollection, instead of getting a proper ArrayCollection I get single element that displays the following when I output it in an alert: obj is: '[object TestVO], [object TestVO], ... [object TestVO]'. If I return a single TestVO object directly instead of a List, I can properly cast the result to my ActionScript TestVO object and view the data properly. It's just returning the List that's giving me problems. Can anyone offer any suggestions please? My Flex result code is: public function result(evt:Object):void { if(evt.type evt.type == ResultEvent.RESULT) { var re:ResultEvent = evt as ResultEvent; var col:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(re.result)); if(col) { Alert.show(obj is: ' + col.getItemAt(0) + '); } else Alert.show(Didn't cast properly!); } } My Java DAO code that returns the list is: public List getList() throws DAOException { List list = new ArrayList(); Connection c = null; try { c = ConnectionHelper.getConnection(); Statement s = c.createStatement(); ResultSet rs = s.executeQuery(SELECT * FROM test); while(rs.next()) { TestVO vo = new TestVO(); vo.id = rs.getInt(id); vo.data = rs.getString(data); list.add(vo); } } catch(Exception e) { e.printStackTrace(); throw new DAOException(e); } finally { ConnectionHelper.close(c); } return list; } -- André Rodrigues Pena LOCUS www.locus.com.br Blog www.techbreak.org