---------- Forwarded message ----------
From: Anil Patel <[EMAIL PROTECTED]>
Date: Mar 18, 2007 4:53 PM
Subject: Re: javascript call to (OFBIZ) service
To: tej minhas <[EMAIL PROTECTED]>
Tej,
One of the ways to call a server side Service from a Webpage is, Post a
request to a request, This request is defined in controller.xml file of you
webapp. The request entry in controller will look like
<request-map uri="lightCreateGlJournalEntry">
<security https="true" auth="true"/>
<event type="jsonservice" invoke="createGlJournalEntry"/>
<response name="success" type="view" value="none"/>
<response name="error" type="view" value="glJournalEntryData"/>
</request-map>
When a controller processes this request it calls createGlJournalEntry
service, in your case this service name will be what ever service you want
to call. In Ofbiz we already have a Request event handler that will call a
service for you and return response as JSON object.
This event is still new so by default its not added to all the controller.
In order to be able to call a service using this event hadler you have to
register it with controller that you do by adding following line to your
controller in the top section,
In the controller of your webapp, add following handler
<handler name="jsonservice" type="request" class="
org.ofbiz.webapp.event.JSONServiceEventHandler"/>
Now you need a javascript function that will call this request from webapp,
this Function will look something like this,
function getGCInfo() {
if (document.setPaymentInformation.addGiftCard.checked) {
dojo.io.bind({url: "<@ofbizUrl>quickAnonGcInfo</@ofbizUrl>",
load: function(type, data, evt){
if(type == "load"){
document.getElementById("giftCardSection").innerHTML = data;
}
},mimetype: "text/html"});
} else {
document.getElementById("giftCardSection").innerHTML = "";
}
}
After this you need to explore how to handle a JSON response.
Regards
Anil Patel
On 3/18/07, tej minhas < [EMAIL PROTECTED]> wrote:
Anil,
Thanks for your response ... however I still do not know how to call such a
service from javascript.
Could you give an example of a call? Thanks
-tej
Anil wrote:
Tej,
I'll use Dojo Ajax in such situations. I have incomplete implementation for
similar use, may be it will help.
In the controller of your webapp, add following handler
<handler name="jsonservice" type="request" class="
org.ofbiz.webapp.event.JSONServiceEventHandler
"/>
Then add a request entry that calls service e.g
<request-map uri="lightCreateGlJournalEntry">
<security https="true" auth="true"/>
<event type="jsonservice" invoke="createGlJournalEntry"/>
<response name="success" type="view" value="none"/>
<response name="error" type="view" value="glJournalEntryData"/>
</request-map>
This request will return a JSON response that you can convert into
Javascript object and read values of interest. you may find example for
this in content component .
I hope this helps.
Regards
Anil
On 3/18/07, tej minhas <
[EMAIL PROTECTED]> wrote:
>
> Can anyone point me to an example or the syntax for calling an (OFBIZ)
> service using javascript.
>
> In particular I am trying to validate a manually entered Product ID when a
> quote item is being added to a quote.
>
> I would like to look the Product ID up in the Product entity and return
> price & description if found ....
>
> Hence I would have to pass the (dynamic) Product ID as a parameter.
>
> Thanks, tej
>