app/gwt/dashboard/src/dashboard/client/Dashboard.java//import類は省くが困ったらgwtのモノを選んどけばたいてい大丈夫
public class Dashboard implements EntryPoint {
public void onModuleLoad() {
final Button button = new Button("Click me");
final Label label = new Label();
button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
//add
ResourceCollection projects = new RailsJsonResourceCollection(
"/projects/", new ResourceFactory() {
public Resource create() {
return (Resource) GWT.create(Project.class);
}
});
projects.find(1, new ResourceResponseHandler() {
public void onSuccess(Resource resource) {
Window.alert("Project(id=1) exists");
}
public void onError(Request request,
Throwable exception) {
Window.alert("Project(id=1) doesn't exist");
}
});
ResourceCollection projects2 = new RailsJsonResourceCollection(
"/projects/", new ResourceFactory() {
public Resource create() {
return (Resource) GWT.create(Project.class);
}
});
projects2.delete(1, new StatusResponseHandler() {
public void onSuccess() {
ResourceCollection projects3 = new RailsJsonResourceCollection(
"/projects/", new ResourceFactory() {
public Resource create() {
return (Resource) GWT
.create(Project.class);
}
});
projects3.find(1, new ResourceResponseHandler() {
public void onSuccess(Resource resource) {
Window.alert("Project(id=1) exists");
}
public void onError(Request request,
Throwable exception) {
Window.alert("Project(id=1) doesn't exist");
}
});
}
public void onError(Request request, Throwable exception) {
}
});
//add
if (label.getText().equals(""))
label.setText("Hello World!");
else
label.setText("");
}
});
//slotは'app/views/dashboard/index.html.erb'内のidでの定義.
//button, labelはそこにハマる.
RootPanel.get("slot1").add(button);
RootPanel.get("slot2").add(label);
}
}
これはid=1のデータを削除する例.流れはまずid=1を取得し成功/不成功をalertで表示する.次にid=1のデータ削除を要求する.成功した際は,再度id=1の取得を試み成功/不成功をalertで表示する.
> rake dashbaord:compile
> script/server
ブラウザにて'http://localhost:3000/dashboard/'へアクセス
0 件のコメント:
コメントを投稿