- Download patchJavascript addon from http://sourceforge.jp/projects/ofbiz-jp/downloads/57320/patchJavascript-0.1.0-v11.04.01.zip and install.
- Rebuild java source by using ant command (no options).
Example
- In this example, modify Jython sample. see http://ofbizj.blogspot.jp/2012/12/jython-script.html
- In directory hot-deploy/helloworld/script/org/ofbiz/test, create file JavaScriptTest.js and edit like bellow.
importPackage(java.lang);
importPackage(java.util);
response = new HashMap();
response.put("result", "OK");
bsf.registerBean("response", response)
System.out.println("Hello !");
- Edit file hot-deploy/helloworld/servicedef/service.xml like bellow.
<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="http://ofbiz.apache.org/dtds/services.xsd">
<description>OFBIZ Test Services</description>
<vendor>OFBiz</vendor>
<version>1.0</version>
<service auth="false" engine="jython" invoke="" location="component://helloworld/script/org/ofbiz/test/JythonScriptTest.py" name="testJythonScript">
<description>Test JythonScript Service</description>
<attribute mode="OUT" name="result" type="String">
</attribute></service><service auth="false" engine="javascript" invoke="" location="component://helloworld/script/org/ofbiz/test/JavaScriptTest.js" name="testJavaScript">
</services>
<description>Test JavaScript Service</description>
<attribute mode="OUT" name="result" type="String">
</attribute></service>
- Edit hot-deploy/helloworld/webapp/helloworld/WEB-INF/controller.xml like bellow.
<request-map uri="main">
<security https="false" auth="false"/>
<event type="service" invoke="testJavaScript"/> <= edit this line
<response name="success" type="view" value="main"/>
</request-map>
- see http://localhost:8080/helloworld/control/main page using browser and see logs. Browser displays "helloworld" and in logs shows "Hello !".
準備
- patchJavascript アドオンを次の場所からダウンロードします http://sourceforge.jp/projects/ofbiz-jp/downloads/57320/patchJavascript-0.1.0-v11.04.01.zip 。その後、adm install patchJavascript-0.1.0-v11.04.01コマンドでインストールします。
- Javaソースがパッチで変更されるのでantコマンドで再ビルドします。antコマンドのオプションは不要です。OFBIZ_HOMEディレクトリに移動してから実行してください。
実行
- patchJythonのサンプルを使用しますのであらかじめ準備してください http://ofbizj.blogspot.jp/2012/12/jython-script.html
- hot-deploy/helloworld/script/org/ofbiz/test ディレクトリに JavaScriptTest.js ファイルを次の内容で作成します。
from java.util import HashMap
response = HashMap()
response.put("result", "OK")
bsf.registerBean("response", response)
print "Hello !"
- hot-deploy/helloworld/servicedef/service.xml ファイルを次の内容に編集します。
<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="http://ofbiz.apache.org/dtds/services.xsd">
<description>OFBIZ Test Services</description>
<vendor>OFBiz</vendor>
<version>1.0</version>
<service auth="false" engine="jython" invoke="" location="component://helloworld/script/org/ofbiz/test/JythonScriptTest.py" name="testJythonScript">
<description>Test JythonScript Service</description>
<attribute mode="OUT" name="result" type="String">
</attribute></service><service auth="false" engine="javascript" invoke="" location="component://helloworld/script/org/ofbiz/test/JavaScriptTest.js" name="testJavaScript">
</services>
<description>Test JavaScript Service</description>
<attribute mode="OUT" name="result" type="String">
</attribute></service>
- hot-deploy/helloworld/webapp/helloworld/WEB-INF/controller.xml ファイルを変更します。
<request-map uri="main">
<security https="false" auth="false"/>
<event type="service" invoke="testJavaScript"/> <= edit this line
<response name="success" type="view" value="main"/>
</request-map>
- 次のURLをブラウザで表示します http://localhost:8080/helloworld/control/main 。画面には "helloworld" が表示されて、ログには "Hello !" が表示されて、サービスが呼び出されたことが確認できます。
0 件のコメント:
コメントを投稿