Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

ArrayCollection in flex and ArrayList in java

Avatar

Level 2















Hi mydears of this world

Here i come along with my problem with the hope that some
one can resolve it

i am totally new to flex and i am working only for the past
3 days in flex. and i learned a little bit.

i want to get the database values which is received from
java object to flex datagrid with the help of data provider.

i did it pretty well according to me. But i could not
produce the result in the data grid . since i am very new . i dont
know what is happening.



my code is here , please help me.



My mxml file : Myadmin.mxml



<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="vertical">

<mx:RemoteObject id="ber" destination="berth"
showBusyCursor="true" fault="faultHandler(event)" >

<mx:method name="getBerth"
result="resultHandler(event)"/>

</mx:RemoteObject>



<mx:Panel id="topPanel" title="MyDatabase" width="100%"
height="40%" enabled="true">

<mx:TextArea id="sql" width="100%" height="100%"/>



<mx:Button label="Execute" click="handleSend()"/>



</mx:Panel>



<mx:Panel id="bottomPanel" title="Results" width="100%"
height="60%" enabled="true">

<mx:DataGrid id="dg" dataProvider="{result}" width="100%"
height="100%"/>





</mx:Panel>

<mx:Label id="resultLabel" text ="Onumae puriyale
ulgathulae" />



<mx:Script>

<![CDATA[



import mx.rpc.events.*;

import mx.collections.*;

import mx.controls.*;

import mx.utils.ObjectUtil;









//cached empty ArrayCollection so that we don't keep
creating

//new ones



private var emptyResults:ArrayCollection = new
ArrayCollection();



[Bindable]

public var result:ArrayCollection = emptyResults;















private function resultHandler(event:ResultEvent):void

{

Alert.show("event.result array results",
ObjectUtil.toString(event.result as ArrayCollection));

result = ArrayCollection(event.result);

var myCursor:IViewCursor=result.createCursor();

var oldLength:int=result.length;



Alert.show(oldLength.toString());









}



private function faultHandler(event:FaultEvent):void

{

Alert.show(event.fault.faultString, "Error");

}



private function handleSend():void

{





ber.getBerth();





}









]]>

</mx:Script>





</mx:Application>



My java Object : Berth.java





package samples.sqladmin;

import java.sql.*;

import java.util.*;

import java.io.*;



public class Berth



{

public static void main(String args[])throws Exception

{

ArrayList list = getBerth();

System.out.println("The List is =" + list);

}



public static ArrayList getBerth()throws Exception {

Connection con = null;

Statement st = null;

ResultSet rs = null;

ResultSetMetaData rsmd = null;

ArrayList list = new ArrayList();

HashMap row=null;

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}catch(ClassNotFoundException cnfe){

System.out.println(cnfe.getMessage());

}

try{

con = DriverManager.getConnection("jdbc:odbc:Jurong","","");

st = con.createStatement();

String sql = "select * from berth ";

rs=st.executeQuery(sql);

rsmd = rs.getMetaData();

int colCount = rsmd.getColumnCount();

while (rs.next()) {

row=new HashMap();

for (int i = 1; i <= colCount; i++) {

row.put(rsmd.getColumnName(i), rs.getString(i));

}

list.add(row);

}



}

catch(SQLException sqle){

System.out.println("enna da yogans eeeeee....");

System.out.println(sqle.getMessage());

}



if(con != null)

con.close();

if(st != null)

st.close();

return list;



}



}



my remote-config file is:



<destination id="berth">

<properties>

<source>samples.sqladmin.Berth</source>

</properties>

</destination>



i got the array collection object in flex but it is not
giving the values which received in java



please help me .

Thanks in advance

yogans.
1 Accepted Solution

Avatar

Correct answer by
Level 2
hi my dear friends



i apologize for putting you all in trouble.I got the
result.The problem is

not with the code. its with my system. The problem is i have
configured

same name for datesource for system DSN and user DSN. after
i delete

one data source name of user DSN . i got it work.



Thanks a lot william, Thanks a lot Nelson for your
spontaneous reply



Thank you

Yogans

View solution in original post

9 Replies

Avatar

Level 3
try



<mx:DataGrid id="dg" dataProvider="{
ber.getBerth.lastResult}" width="100%" height="100%">

<mx:columns>

<mx:DataGridColumn dataField="yourColumnname" />

</mx:columns>

</mx:DataGrid>

Avatar

Level 2
hi my friend sanclementetech

i really thank you for your instant reply. i did not check
this yet .After checking this

i will send my reply.

thank you thank you a lot

Avatar

Level 2
Hi friend!.

Still i dont get the Result. please check this and tell me
what is the problem. i am very new guy to flex and i dont

have proper documentation for dataservice. please, i
struggling with this problem for more than a week.



thanks in advance, i am awating for your reply.

thanks and Regards

s.yogans

Avatar

Level 3
Hi,



I looked at your code. I couldn't see find any problem. I
found the Alert in your resultHandler. You could get the
resultHandler called with the values, but the dataGrid didn't show
anything, right? Not sure what went wrong for the databinding. You
can take a look into the generated code. I don't think there is any
conflict with the variable name "result". However, you can try
assigning the result to the datagrid in the resultHandler.
(dg.dataProvider=event.result) If it works, it should be
databinding issue. Take a look into the *.binding-generated.as



William

Avatar

Level 2
Hi friend , still i dont get the result . My problem is when
i run the java remote

object program in the command prompt , it produces the
database values in the

Arraylist But if the same program with out main function ,
and contains only one function namely getBerth(). called through
flex .it does not work. and it says

that length of the arraycollection is zero.



please find the problem and give me a good solution friends.
i will be so thank ful to you all in my life. or else please give
me some sample code which retreives database values from the
database to flex onnly through java remote object.





Thannks in advance



Please help this poor guy.



thanks and regards

yogans

Avatar

Level 3
Hi,

Not sure why this happened. I think you should check the log
to make sure no java exception found. Also turning on Flex debug in
the services-config.xml and filters only have endpoint.* to see the
request and response.



Thanks

William

Avatar

Level 3
yogans -



What application server are you running?

Are you running your application from within FlexBuilder or
are you running your application in a browser that you navigate to?



Ken

Avatar

Level 2
Hi Nelson.

Actually i copied samples.war file from the samples folder
which comes along with flex data services package.and paste it in
webapps of Apache

Tomcat server. The example programs in the samples folder is
running properly. in fact i done one example program of myself
which has database connection and returns a String, that is also
working good. But when i tried to get all the values from the
database and put into a arraylist of map objects, it does not work
as i thought.



please help me. and i am in bad need of this solution or else
please supply one example program that retrives database values
from the table using java object.



Thanks

yours friend

yogans

Avatar

Correct answer by
Level 2
hi my dear friends



i apologize for putting you all in trouble.I got the
result.The problem is

not with the code. its with my system. The problem is i have
configured

same name for datesource for system DSN and user DSN. after
i delete

one data source name of user DSN . i got it work.



Thanks a lot william, Thanks a lot Nelson for your
spontaneous reply



Thank you

Yogans