0 Replies Latest reply on Aug 1, 2008 5:33 AM by gomoliako

    Remote Object, type problem

    gomoliako
      Hi,

      when I call a java function with a remote object and assign the event.result to an AS object, Strings are returned but all integeres are always 0.

      Here the code of my problem...

      === User.as ===
      import mx.collections.ArrayCollection;
      [Bindable]
      [RemoteClass(alias="com.awi.user.User")]
      public class User
      {
      public var id:int;
      public var name:String;
      public var surname:String;
      public var username:String;
      public var password:String;
      public var created:int;
      public var last_login:int;
      public var group_id:int;

      public function User(){}
      }

      === awi.mxml ===
      ...
      private function faultHandler(event:FaultEvent):void
      {
      Alert.show("Error: " + ObjectUtil.toString(event.fault) );
      }

      private function usrResultHandler(event:ResultEvent):void
      {
      user = event.result as User;
      Alert.show(ObjectUtil.toString(user));
      }

      [Bindable]
      public var userRO:RemoteObject;

      private function checkLogin(username:String, password:String):void
      {
      uname = username;

      userRO = new RemoteObject();
      userRO.destination = "userservice";
      userRO.login.addEventListener("result", loginResultHandler);
      userRO.addEventListener("fault", faultHandler);
      userRO.login(username, password);

      }

      [Bindable]
      public var shRO:RemoteObject;
      public var usrRO:RemoteObject;

      private function loginResultHandler(event:ResultEvent):void
      {
      var user:User = new User();

      if(event.result)
      {

      usrRO = new RemoteObject();
      usrRO.destination = "userservice";
      usrRO.getUserByUserName.addEventListener("result", usrResultHandler);
      usrRO.addEventListener("fault", faultHandler);
      usrRO.getUserByUserName(uname);

      Alert.show('Welcome ' + uname);
      currentState = "control_panel";

      main.title = "Welcome to AWI - " + uname + " " + user.username;
      }
      else
      {
      Alert.show('Invalid username/password');
      }
      }
      ...

      === UserService.java ===
      ...
      public User getUser(int userId) throws DAOException {

      User user = new User();
      Connection c = null;

      try {
      c = ConnectionHelper.getConnection();
      PreparedStatement ps = c.prepareStatement("SELECT * FROM user WHERE id=?");
      ps.setInt(1, userId);
      ResultSet rs = ps.executeQuery();
      if (rs.next()) {
      user = new User();
      user.setID(rs.getInt("id"));
      user.setName(rs.getString("name"));
      user.setSurname(rs.getString("surname"));
      user.setUsername(rs.getString("username"));
      user.setPassword(rs.getString("password"));
      user.setCreated(rs.getTimestamp("created"));
      user.setLastLogin(rs.getTimestamp("last_login"));
      user.setGroupID(rs.getInt("group_id"));
      }
      } catch (Exception e) {
      e.printStackTrace();
      throw new DAOException(e);
      } finally {
      ConnectionHelper.close(c);
      }
      return user;
      }
      ...

      The Java method was tested and works great, but called like RemoteObject no return the integers.

      Can anyone help me?

      Regards,
      Junior