GUI 기반 프로그래밍 전형이다. SDK가 제공하는 인터페이스 구현(implements)를 통해 이벤트 핸들러를 정의한다.
실제 비즈니스 로직은 모아 두었다.(sendNameToServer() 메소드)
GAE/J 가 원격 통신을 추상화시켜주겠지. 직관적인 콜백 메소드 이름(onFailure, on Success)탓에 쉽게 코드를 이해할 수 있다.
다른 GUI 프로그래밍과 다른 부분은 아래 코드다.
RootPanel 클래스의 add() 메소드로 HTML의 특정 영역을 지정하고, GWT 컴포넌트를 삽입한다. HTML 영역지정 코드는 다음과 같다.
이번에는 GAE/J Eclipse 개발환경의 특징이다. SDK로 서버가 배포되는 점에서 GAE/J의 포지션을 알 수 있는 부분이지만, 편리해서 마음에 든다.
얏호! 수 초의 작업 후에 배포에 성공했다.
http://ahnyounghoe.appspot.com/
class MyHandler implements ClickHandler, KeyUpHandler {
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
sendNameToServer();
}
/**
* Fired when the user types in the nameField.
*/
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
sendNameToServer();
}
}
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
sendNameToServer();
}
/**
* Fired when the user types in the nameField.
*/
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
sendNameToServer();
}
}
실제 비즈니스 로직은 모아 두었다.(sendNameToServer() 메소드)
private void sendNameToServer() {
<중략>
greetingService.greetServer(textToServer,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
<중략>
}
public void onSuccess(String result) {
<중략>
}
});
<중략>
greetingService.greetServer(textToServer,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
<중략>
}
public void onSuccess(String result) {
<중략>
}
});
GAE/J 가 원격 통신을 추상화시켜주겠지. 직관적인 콜백 메소드 이름(onFailure, on Success)탓에 쉽게 코드를 이해할 수 있다.
다른 GUI 프로그래밍과 다른 부분은 아래 코드다.
RootPanel.get("nameFieldContainer").add(nameField);
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);
RootPanel 클래스의 add() 메소드로 HTML의 특정 영역을 지정하고, GWT 컴포넌트를 삽입한다. HTML 영역지정 코드는 다음과 같다.
<td id="nameFieldContainer"></td>
<td id="sendButtonContainer"></td>
<td id="sendButtonContainer"></td>
이번에는 GAE/J Eclipse 개발환경의 특징이다. SDK로 서버가 배포되는 점에서 GAE/J의 포지션을 알 수 있는 부분이지만, 편리해서 마음에 든다.
The development server is part of the SDK. You can‘t use your own development server for App Engine debugging and testing. The App Engine JRE differs from other implementations.
얏호! 수 초의 작업 후에 배포에 성공했다.
http://ahnyounghoe.appspot.com/
