开发者

instead of arrayCollection

开发者 https://www.devze.com 2023-03-04 20:28 出处:网络
I am trying to return values from java into flex front end using BlazeDs.Successfully blazeds is connecting while retrieving the values it is showing [object Asynvtoken] am not getting values from jav

I am trying to return values from java into flex front end using BlazeDs.Successfully blazeds is connecting while retrieving the values it is showing [object Asynvtoken] am not getting values from 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开发者_如何学Python: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 is connected");    

         String strSQL = "select * from 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();
        }
        finally
        {
            try
            {
                connection.close();
            }
            catch (Exception ignored) 
            {

            }
        }
         return ls;
    }
}

Please help me if anyone knows the solution.


Keep in mind that calls to RPC services are asynchronous.

At first you call the remote function getUser. This request is send to the server and the getOperation function returns immediatly. The result of this call is an AsyncToken object which is not the result of the call of getUser. The token is a part of the Asynchronous Completion Token design pattern. After the RPC function returns your client will get the response in the result handler which is your declared result function. The result is part of the ResultEvent parameter.

So the 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;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消