RPC response null

I have some code meant to check in someone’s login and password, and it returns a User object I fill from SQL in the UserServiceImpl.java. When I get back to the onSuccess(User result){} the User object looks good. I then set it into a local User object to reference later, but everything is now null. Please help!

I have noticed with my println statements that the prints using the service will print after ones below the fetch() call. Does this mean that the AsyncCallback isn’t done processing when I attempt to put it’s values into the user instance of User? If so, how do I make sure it’s done first?

public boolean logIn(String name, String password){
	final User user = new User();
	//Do some crap here to make sure they have the right name and password
	try {
		loginService.fetch (name, password, new AsyncCallback<User> () {
	        public void onFailure (Throwable caught) {
	        	System.out.println("Failure at retrieving User info for login");
	        }
	        public void onSuccess (User result) {
	        	//This prints out the first/last name from User object
	        	String fullname = user.getFirst_name() + "." + user.getLast_name();
	        	copyValues(result , user);
	        }
	    });
		//This becomes null.null
		String fullname = user.getFirst_name() + "." + user.getLast_name();
		System.out.println("Name from DB just before checking if they match is: " + fullname);
		if(name.equals(fullname)){
			if(password.equals(user.getUser_password())){
				System.out.println("I got to return true!");
				//Set up the User object here, then return true
				return true;
			}
		}
	} catch( Exception e){
		e.printStackTrace();
	}
	return false;
}

private void copyValues(User result, User user){
	user.setUser_id(result.getUser_id());
	user.setFirst_name(result.getFirst_name());
	user.setLast_name(result.getLast_name());
	user.setUser_email(result.getUser_email());
	user.setUser_position(result.getUser_position());
	user.setUser_title(result.getUser_title());	
}

Bad code and not smartgwt related, but change to:

User user = null;
...
public void onSuccess (User result) {
user = result;
}
...
System.out.println("My user is " + user.getFirst_name() + "." + user.getLast_name());

I had it like that, was just trying random stuff to see if I could get it to work.

Sorry shouldn’t be that end ‘}’, you need to wrap your code inside the success function to guarantee your code doesn’t execute before it returns.