私はDojoを初めて使用します(実際、すべてのフロントエンドプログラミングでは、JavaとC#で何年もサーバー側で作業しています)。私は現在、Java Server Faces(JSF)2.1を使用しており、JSFとDojo Grid(dgrid)をDojo1.8で使用して簡単なデモをまとめようとしています。ガントチャートの作成方法を示すdgridサイトの例がありますが、この例では、アプリケーションサーバーからJSONデータを抽出して関数にフィードする方法を示していません。問題は、脳をARMに巻き付けるのに苦労していることです。そこでの経験が、私の痛みの一部を軽減するのに役立つことを願っています。ここにいくつかのコードがあります:
これは私が作成したhtmlファイルにあり、ロード時にガントを作成するだけです。
<script>
require([ "gantt/GanttGrid", "gantt/data" ], function(GanttGrid, data){
// Instantiate the GanttGrid using predefined test data
new GanttGrid({
store: data,
query: {
// Only tasks with no parent task should be displayed in the root of the chart
parent: undefined
}
}, "gantt");
});
</script>
「データ」は別のjsファイルから取得され、DOJOのMemoryオブジェクトに丸呑みされたJSONデータです。
define(["dojo/store/Memory"],function(Memory){
return new Memory({data:[
{name: "100", start: 1327900000000, end: 1328300000000, completed: 0.9, id: 1},
{name: "101", start: 1328100000000, end: 1328400000000, completed: 0.9, id: 2},
{name: "102", start: 1329100000000, end: 1329800000000, completed: 0.4, dependencies:[1], id: 3},
{name: "103", start: 1328400000000, end: 1328900000000, completed: 0.4, dependencies:[1], id: 4},
{name: "104", start: 1329000000000, end: 1329800000000, completed: 0.4, id: 5},
{name: "105", start: 1329000000000, end: 1329400000000, completed: 0.4, id: 6},
{name: "106", start: 1329400000000, end: 1329800000000, completed: 0.4, id: 7}
],
getChildren: function(parent, options){
return this.query({parent: parent.id}, options);
},
mayHaveChildren: function(parent){
return parent.hasChildren;
}
});});
さて、私が欲しいのは、バックエンドでいくつかのロジックを実行し、DOJOのメモリストアに追加してGanttGridに渡すことができるJSONデータを返すJSFマネージドBeanのメソッドを呼び出すことができることですが、私は思えませんajaxリクエストでそれを実現する方法を理解するために。
これが、Beanからデータを正常に取得して画面に表示するXHTMLファイルにあるものです。
<fieldset>
<h:form id="schedulerForm">
<h:commandButton value="Execute Demo" id="executeDemo">
<f:ajax event="click" listener="#{autoScheduler.executeDemo}" render="result" />
</h:commandButton>
<p />
<h:outputText id="result" value="#{autoScheduler.result}" />
</h:form>
</fieldset>
私が欲しいのは、JSF BeanでexecuteDemoの結果をキャプチャして、GanttGridを作成する関数に渡すことです。DOJOの「オン」機能を使用してみましたが、ボタンのクリックをキャプチャすることしかできません(私が言えることから)...実行がいつ完了したかを知る方法がわからないので、 Beanからデータを取得し、グラフを作成します。最大の問題は、DOJOリクエストモジュールを使用してJSFBeanを呼び出す方法がわからないことです。
誰かがこれを達成する簡単な方法を知っていることを願っています。助けてくれてありがとう!さらに情報が必要な場合はお知らせください...関連するすべてのコードを含めようとしました。
-ポール