package ${modulePackage}.client.controller;

import org.cruxframework.crux.core.client.screen.Screen;
import org.cruxframework.crux.core.client.controller.Controller;
import org.cruxframework.crux.core.client.controller.Expose;
import org.cruxframework.crux.core.client.ioc.Inject;
import org.cruxframework.crux.core.client.rpc.AsyncCallbackAdapter;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

import ${modulePackage}.client.remote.GreetingServiceAsync;

@Controller(value="myController")
public class MyController {
	
	@Inject
	private GreetingServiceAsync service; 
	
	public void setService(GreetingServiceAsync service)
	{
		this.service = service;
	}
	
	@Expose
	public void sayHello() {
		
		TextBox textBox = Screen.get("nameTextBox", TextBox.class);
		final String name = textBox.getValue();
		
		service.getHelloMessage(name, new AsyncCallbackAdapter<String>(){

				@Override
				public void onComplete(String result){
					Label label = Screen.get("greetingLabel", Label.class);
					label.setText(result);		
				}
			}
		);
	}
}