You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by "Robert G." <ga...@mercon24.de> on 2012/07/03 18:20:35 UTC
Response from java Method to client - Ajax call
hey guys,
I use javascript to do some things. To get a consistent status of the user
preferences I want to store some variables in the session object.
I created java methods to check if the session key exists, to store a value
or to remove them.
With an ajax call I call the java method with the way over the
controller.xml. That works. But now I get the respons like:
<response name="isInSession"... />
<response name="isNotInSession" ... />
I dont want to call with them a view, I want to get a response directly like
a callback to my ajax request. Is that possible? Which type etc. I use in
the response?
I want to check in the ajax "success" sth. like:
/
if (...isInsession) {
do this
} else {
do sth else
}/
I know, that I can do the not that nice way, by calling a view, and request
it from the header in the callback...but I hope this is going more easy :)
btw. I checked a lot of posts in that forum, but couldnt find a good answer
for me (maybe cause its not possible)
pleeeeaasse help :)
Robert
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by Deepak Agarwal <da...@gmail.com>.
I will do it in following manner:
<request-map uri="checkInSession">
<security https="false" auth="false"/>
<event type="service"
path="org.ofbiz.ecommerce.general.HelperMethods" invoke="checkInSession"/>
<response name="response" type="request" value="json" />
<response name="error" type="none" />
</request-map>
My checkInSession will return Map<String, Object> in response and I will
recv json at my browser ajax callback.
On Wed, Jul 4, 2012 at 5:19 PM, Robert G. <ga...@mercon24.de> wrote:
> sorry, I have not got it and have to ask again :)
>
> I call a mapping to put things into the request object with that:
>
> /<request-map uri="checkInSession">
> <security https="false" auth="false"/>
> <event type="java" path="org.ofbiz.ecommerce.general.HelperMethods"
> invoke="checkInSession"/>
> <response name="response" type="request" value="json" />
> <response name="error" type="none" />
> </request-map>/
>
> then the method: checkInSession does the things into the http request
> object
>
> now I dont know how to automatical call the
> "jsonResponseFromRequestAttributes"
>
> or is it automatically called with the "<response name="response"
> type="request" value="json" />" ?
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634446.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
> --
> Thanks,
> Deepak Agarwal,
>
> Paxcel Technologies Pvt Ltd.
> Hartron Complex, Sector 18, Gurgaon, India.
> E-Mail: deepak.agarwal@paxcel.net
> Mobile: +91 9910322604
>
>
Re: Response from java Method to client - Ajax call
Posted by "Robert G." <ga...@mercon24.de>.
I got it before, but didnt worked, but now I realised that I made a mistake
by the java method response.
Thank you for your help @all!!! It works now :)
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634509.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by jyoti <jy...@viithiisys.com>.
Hi Robert,
In case of json, response is in the form of objects and these
objects can be easily manipulated in the success of ajax reponse. For
example,
$.ajax({
type : 'POST/GET',
url : url,
data : data,
success: function(data){
var obj1 = data.obj1;
var obj2 = data.obj2;
}
})
Thanks,
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634486.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by Deepak Dixit <de...@hotwaxmedia.com>.
Hi Robbert,
You can take references of any of the js file.
Please refer ecommerce/checkoutprocess.js (setShippingOption()) .
also please visit :http://api.jquery.com/jQuery.ajax/
Thanks & Regards
--
Deepak Dixit
HotWax Media Pvt. Ltd.
www.hotwaxmedia.com
Contact :- +91-98267-54548
Skype :- deepakdixit
On Jul 5, 2012, at 1:45 AM, Robert G. wrote:
> sorry for disturbing again, how is the ajax syntax to get this json response
> object? I cannot find a working solution. After that I got it :)
>
> please help that last time on that subject. Thanks Robert
>
>
>
>
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634464.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by "Robert G." <ga...@mercon24.de>.
sorry for disturbing again, how is the ajax syntax to get this json response
object? I cannot find a working solution. After that I got it :)
please help that last time on that subject. Thanks Robert
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634464.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by "Robert G." <ga...@mercon24.de>.
great! Thanks :)
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634458.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by Deepak Dixit <de...@hotwaxmedia.com>.
You can include the common-controller.xml in you custom controller.xml using include tag.
<include location="component://common/webcommon/WEB-INF/common-controller.xml"/>
You can refer any controller.xml (ordermgr, party, etc) for example
.
If you don't want to include common-controller.xml then you can simply add json request map uri in you custom controller.xml
Thanks & Regards
--
Deepak Dixit
HotWax Media Pvt. Ltd.
www.hotwaxmedia.com
Contact :- +91-98267-54548
Skype :- deepakdixit
On Jul 4, 2012, at 6:16 PM, Robert G. wrote:
> just a last small question:
>
> the mappings in the common-controller.xml are they just like a library,
> where I copy it into my controller.xml, or can I call the mapiing in the
> common-controller.xml out of the controller.xml?
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634454.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by "Robert G." <ga...@mercon24.de>.
just a last small question:
the mappings in the common-controller.xml are they just like a library,
where I copy it into my controller.xml, or can I call the mapiing in the
common-controller.xml out of the controller.xml?
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634454.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by "Robert G." <ga...@mercon24.de>.
ahh ok, I think now I got it:
/<request-map uri="checkInSession">
<security https="false" auth="false"/>
<event type="java" path="org.ofbiz.ecommerce.general.HelperMethods"
invoke="checkInSession"/>
<response name="response" type="request" value="json" />
<response name="error" type="none" />
</request-map>
/
this calls than the uri mapping for uri = "json":
/<request-map uri="json">
<security direct-request="false"/>
<event type="java" path="org.ofbiz.common.CommonEvents"
invoke="jsonResponseFromRequestAttributes"/>
<response name="success" type="none"/>
</request-map> /
and with that I get the http request into a json object, which I can get in
my ajax thing :)
great, I will try it. Thank you all so much for helping me that fast, cause
now with the session thing I can create with JS / Ajax things more functions
and solutions....
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634453.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by Deepak Dixit <de...@hotwaxmedia.com>.
Hello Robbert,
Let me try to explain:
On Jul 4, 2012, at 5:19 PM, Robert G. wrote:
> sorry, I have not got it and have to ask again :)
>
> I call a mapping to put things into the request object with that:
>
> /<request-map uri="checkInSession">
> <security https="false" auth="false"/>
> <event type="java" path="org.ofbiz.ecommerce.general.HelperMethods"
> invoke="checkInSession"/>
> <response name="response" type="request" value="json" />
Here you are using request-chain feature, if response matches with name then it call another request.
> <response name="error" type="none" />
> </request-map>/
If you call an request via ajax call then you need to parse response in json format, for this there is an request json that parse the responses to the json formate,
<request-map uri="json">
<security direct-request="false"/>
<event type="java" path="org.ofbiz.common.CommonEvents" invoke="jsonResponseFromRequestAttributes"/>
<response name="success" type="none"/>
</request-map>
Please see the jsonResponseFromRequestAttributes method form commonEvents.java, this method take the http request and response and set the content-type as "application/x-json" and
part pull out the service response from the request attribute and create a JSON Object for return.
>
> then the method: checkInSession does the things into the http request object
>
> now I dont know how to automatical call the
> "jsonResponseFromRequestAttributes"
>
> or is it automatically called with the "<response name="response"
> type="request" value="json" />" ?
Yes json request call automatically (as request chain).
Thanks & Regards
--
Deepak Dixit
HotWax Media Pvt. Ltd.
www.hotwaxmedia.com
Contact :- +91-98267-54548
Skype :- deepakdixit
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634446.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by "Robert G." <ga...@mercon24.de>.
sorry, I have not got it and have to ask again :)
I call a mapping to put things into the request object with that:
/<request-map uri="checkInSession">
<security https="false" auth="false"/>
<event type="java" path="org.ofbiz.ecommerce.general.HelperMethods"
invoke="checkInSession"/>
<response name="response" type="request" value="json" />
<response name="error" type="none" />
</request-map>/
then the method: checkInSession does the things into the http request object
now I dont know how to automatical call the
"jsonResponseFromRequestAttributes"
or is it automatically called with the "<response name="response"
type="request" value="json" />" ?
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634446.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by Deepak Agarwal <da...@gmail.com>.
<request-map uri="json">
<security direct-request="false"/>
<event type="java" path="org.ofbiz.common.
CommonEvents"
invoke="jsonResponseFromRequestAttributes"/>
<response name="success" type="request" value="json"/>
</request-map>
Just use above and u will get the json in your ajax callback.
On Wed, Jul 4, 2012 at 4:01 PM, Robert G. <ga...@mercon24.de> wrote:
> Ah I think the jason thing is what I need...
>
> so you mean I put it into the request and get it with:
>
> /<request-map uri="json">
> <security direct-request="false"/>
> <event type="java" path="org.ofbiz.common.CommonEvents"
> invoke="jsonResponseFromRequestAttributes"/>
> <response name="success" type="none"/>
> </request-map>/
>
> ?
>
> I dont really know how to handle "json" as I see...the java method writes
> the request object into a json object...so that I can call it maybe with
> ajax...how would i call it?
>
> --> This I can check on json.org :). nevertheless, if you have a fast
> answer, I would be happy :)
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634441.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
> --
> Thanks,
> Deepak Agarwal,
>
> Paxcel Technologies Pvt Ltd.
> Hartron Complex, Sector 18, Gurgaon, India.
> E-Mail: deepak.agarwal@paxcel.net
> Mobile: +91 9910322604
>
>
Re: Response from java Method to client - Ajax call
Posted by "Robert G." <ga...@mercon24.de>.
Ah I think the jason thing is what I need...
so you mean I put it into the request and get it with:
/<request-map uri="json">
<security direct-request="false"/>
<event type="java" path="org.ofbiz.common.CommonEvents"
invoke="jsonResponseFromRequestAttributes"/>
<response name="success" type="none"/>
</request-map>/
?
I dont really know how to handle "json" as I see...the java method writes
the request object into a json object...so that I can call it maybe with
ajax...how would i call it?
--> This I can check on json.org :). nevertheless, if you have a fast
answer, I would be happy :)
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634441.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by Deepak Dixit <de...@hotwaxmedia.com>.
Hi Robert,
I think you looking for :
<response name="response" type="request" value="json" />
Please refere the json request in common-controller.xml for json response handling. You can also trace the getConfigDetailsEvents request form ordermgr controller.
Instead of return isInSession or isNotSession as a response you can put value in request as request.setAttribute and get it from json resoponse.
Thanks & Regards
--
Deepak Dixit
HotWax Media Pvt. Ltd.
www.hotwaxmedia.com
Contact :- +91-98267-54548
Skype :- deepakdixit
On Jul 3, 2012, at 9:50 PM, Robert G. wrote:
> hey guys,
>
> I use javascript to do some things. To get a consistent status of the user
> preferences I want to store some variables in the session object.
>
> I created java methods to check if the session key exists, to store a value
> or to remove them.
>
> With an ajax call I call the java method with the way over the
> controller.xml. That works. But now I get the respons like:
>
> <response name="isInSession"... />
> <response name="isNotInSession" ... />
>
> I dont want to call with them a view, I want to get a response directly like
> a callback to my ajax request. Is that possible? Which type etc. I use in
> the response?
>
> I want to check in the ajax "success" sth. like:
>
> /
> if (...isInsession) {
> do this
> } else {
> do sth else
> }/
>
> I know, that I can do the not that nice way, by calling a view, and request
> it from the header in the callback...but I hope this is going more easy :)
>
> btw. I checked a lot of posts in that forum, but couldnt find a good answer
> for me (maybe cause its not possible)
>
> pleeeeaasse help :)
>
> Robert
>
>
>
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
RE: Response from java Method to client - Ajax call
Posted by Skip <sk...@thedevers.org>.
You can also do a json response directly from the called service, but you'll
need the response object, so call it as an event instead of a service. Once
you get the response object, the rest is easy (jsonString is the json
formatted string you want to return to the browser):
//Skip System.out.println("Sending Jason response String " + jsonString);
response.setContentType("application/x-json");
try
{
response.setContentLength(jsonString.getBytes("UTF-8").length);
} catch (UnsupportedEncodingException e) {
response.setContentLength(jsonString.length());
}
Writer out;
try {
out = response.getWriter();
out.write(jsonString);
out.flush();
} catch (IOException e) {
Debug.logError(e, "Failed to get response writer", module);
result = "error";
}
-----Original Message-----
From: Nandani Aggarwal [mailto:nandani.aggarwal@paxcel.net]
Sent: Tuesday, July 03, 2012 9:20 PM
To: user@ofbiz.apache.org
Subject: Re: Response from java Method to client - Ajax call
If you want to call another java method on basis of responses you get then
you may use :
<response name="success" type="request" value="JAVA_METHOD_NAME" />
<handler name="java" type="request"
class="org.ofbiz.webapp.event.JavaEventHandler" />
Thanks
Nandani
On Tue, Jul 3, 2012 at 11:51 PM, Robert G. <ga...@mercon24.de> wrote:
> what does that do? How can I handle the response in the ajax callback?
>
> --
> View this message in context:
>
http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-c
all-tp4634402p4634411.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
Re: Response from java Method to client - Ajax call
Posted by Nandani Aggarwal <na...@paxcel.net>.
If you want to call another java method on basis of responses you get then
you may use :
<response name="success" type="request" value="JAVA_METHOD_NAME" />
<handler name="java" type="request"
class="org.ofbiz.webapp.event.JavaEventHandler" />
Thanks
Nandani
On Tue, Jul 3, 2012 at 11:51 PM, Robert G. <ga...@mercon24.de> wrote:
> what does that do? How can I handle the response in the ajax callback?
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634411.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
Re: Response from java Method to client - Ajax call
Posted by "Robert G." <ga...@mercon24.de>.
what does that do? How can I handle the response in the ajax callback?
--
View this message in context: http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402p4634411.html
Sent from the OFBiz - User mailing list archive at Nabble.com.
Re: Response from java Method to client - Ajax call
Posted by Deepak Agarwal <da...@gmail.com>.
<response name="success" type="none" />is that what you are looking for ?
On Tue, Jul 3, 2012 at 9:50 PM, Robert G. <ga...@mercon24.de> wrote:
> hey guys,
>
> I use javascript to do some things. To get a consistent status of the user
> preferences I want to store some variables in the session object.
>
> I created java methods to check if the session key exists, to store a value
> or to remove them.
>
> With an ajax call I call the java method with the way over the
> controller.xml. That works. But now I get the respons like:
>
> <response name="isInSession"... />
> <response name="isNotInSession" ... />
>
> I dont want to call with them a view, I want to get a response directly
> like
> a callback to my ajax request. Is that possible? Which type etc. I use in
> the response?
>
> I want to check in the ajax "success" sth. like:
>
> /
> if (...isInsession) {
> do this
> } else {
> do sth else
> }/
>
> I know, that I can do the not that nice way, by calling a view, and request
> it from the header in the callback...but I hope this is going more easy :)
>
> btw. I checked a lot of posts in that forum, but couldnt find a good answer
> for me (maybe cause its not possible)
>
> pleeeeaasse help :)
>
> Robert
>
>
>
>
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/Response-from-java-Method-to-client-Ajax-call-tp4634402.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
> --
> Thanks,
> Deepak Agarwal,
>
> Paxcel Technologies Pvt Ltd.
> Hartron Complex, Sector 18, Gurgaon, India.
> E-Mail: deepak.agarwal@paxcel.net
> Mobile: +91 9910322604
>
>