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 |
<response name="success" type="none" />is that what you are looking for ?
On Tue, Jul 3, 2012 at 9:50 PM, Robert G. <[hidden email]> 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: [hidden email] > Mobile: +91 9910322604 > > |
This post was updated on .
what does that do? How can I handle the response in the ajax callback?
My ajax call is like: $.ajax ({ type: "POST", url: "/ecommerce/control/checkInSession", data: dataString, success: function(result) { Here I wanna know if this Key is in session or not, that I can do conditions on it } But how to call the return value from the java method? Cause the method is on serverside, I think I have to call sth with ajax, but how? The "result" is empty, even when I do type="none" in the controller.xml as you mentioned... |
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. <[hidden email]> 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. > |
In reply to this post by Robert Gan
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. smime.p7s (6K) Download Attachment |
This post was updated on .
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> ? how can I call this mapping? or is it called automatically? Cause the response type is : <response name="response" type="request" value="json" /> Does this call the above mapping? 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 :) |
<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. <[hidden email]> 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: [hidden email] > Mobile: +91 9910322604 > > |
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" />" ? |
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. smime.p7s (6K) Download Attachment |
In reply to this post by Robert Gan
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. <[hidden email]> 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: [hidden email] > Mobile: +91 9910322604 > > |
In reply to this post by Deepak Dixit-2
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.... |
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? |
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. smime.p7s (6K) Download Attachment |
great! Thanks :)
|
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 |
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. smime.p7s (6K) Download Attachment |
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,
Jyoti Sharma
|
In reply to this post by Nandani
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:[hidden email]] Sent: Tuesday, July 03, 2012 9:20 PM To: [hidden email] 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. <[hidden email]> 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. > |
In reply to this post by jyoti
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 :) |
Free forum by Nabble | Edit this page |