java - instead of arrayCollection -
i trying return values java flex front end using blazeds.successfully blazeds connecting while retrieving values showing [object asynvtoken] not getting values java method.
my flex code is:
<fx:script> <![cdata[ import mx.collections.arraycollection; import mx.controls.alert; import mx.rpc.asynctoken; import mx.rpc.events.faultevent; import mx.rpc.events.resultevent; public function get_user():void { var token:asynctoken = ro.getoperation('getuser').send(); user_grid.dataprovider = token.tostring(); alert.show(user_grid.dataprovider.tostring()); } private function fault(e:faultevent):void { alert.show("code:\n" + e.fault.faultcode + "\n\nmessage:\n" + e.fault.faultstring + "\n\ndetail:\n" + e.fault.faultdetail); } private function result(e:resultevent):void { userbtn.visible = false; lnkbtn.visible = true; } ]]> </fx:script> <fx:declarations> <!-- place non-visual elements (e.g., services, value objects) here --> <s:remoteobject id="ro" source="com.freelancer.getuser" fault="fault(event)" destination="blazedsservice"> <s:method name="getuser" result="result(event)"/> </s:remoteobject> </fx:declarations> <mx:datagrid id="user_grid" x="-1" y="-1" width="705" height="356"> <mx:columns> <mx:datagridcolumn headertext="id" datafield="id"/> <mx:datagridcolumn headertext="name" datafield="name"/> <mx:datagridcolumn headertext="password" datafield="pwd"/> </mx:columns> </mx:datagrid> <s:button x="322" y="429" id="userbtn" label="get user" width="98" height="23" cornerradius="10" click="get_user()"/> <mx:linkbutton x="331" y="429" id="lnkbtn" visible="false" label="connected please wait loading . . ."/>
my java code is:
public class getuser { public static void main(string[] argv) { system.out.println("-------- postgresql " + "jdbc connection testing ----------"); getuser(); } public static list<user> getuser() { list<user> ls=new arraylist<user>(); string host = "test"; string port = "1234"; string dbname = "test"; connection connection = null; try { connection = drivermanager.getconnection( "jdbc:postgresql://" + host + ":" + port + "/" + dbname,"user", "user"); system.out.println("database connected"); string strsql = "select * test"; statement st = connection.createstatement(); resultset rs=st.executequery(strsql); system.out.println("hi,query executed"); while(rs.next()) { user user = new user(); user.setid(rs.getint("id")); user.setname(rs.getstring("name")); user.setpwd(rs.getstring("pwd")); ls.add(user); } } catch(exception e) { system.out.println(); } { try { connection.close(); } catch (exception ignored) { } } return ls; } }
please me if knows solution.
keep in mind calls rpc services asynchronous.
at first call remote function getuser
. request send server , getoperation
function returns immediatly. result of call asynctoken
object not result of call of getuser
. token part of asynchronous completion token design pattern. after rpc function returns client response in result handler declared result
function. result part of resultevent
parameter.
so following should work:
public function get_user():void { var token:asynctoken = ro.getoperation('getuser').send(); } private function result(e:resultevent):void { user_grid.dataprovider = e.result; userbtn.visible = false; lnkbtn.visible = true; }
Comments
Post a Comment