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.findAll(new CollectionResponseHandler() {
public void onSuccess(Collection resources) {
String msg= "[";
Iterator projectIter= resources.iterator();
while(projectIter.hasNext()) {
Project p= (Project) projectIter.next();
msg += (msg.length()>1)?", ":"";
msg += p.getName();
}
msg += "]";
label.setText(msg);
}
public void onError(Request request, Throwable exception) {
label.setText("Something went wrong.");
}
});
//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);
}
}
これは登録されている全てのProjectを取ってくる例.取ってきた結果のnameを文字列に詰め込んでlabelに入れているあたりがちょっと新しいかなw.
> rake dashbaord:compile
> script/server
ブラウザにて'http://localhost:3000/dashboard/'へアクセス
0 件のコメント:
コメントを投稿