Solved
EXTJS need to parse response from AEM servlet and How to do?
There is a case to Add a button into sidekick, which need to be disable(grey) or enable also, controlled by one condition that data stored in AEM, please see following code:
CQ.Ext.ns("MyClientLib"); var resultFromAEM; MyClientLib.ContentFinder = { addGsTranslate: function(sk){ var pagePanel = sk.panels["PAGE"]; var button = pagePanel.findBy(function(comp){ return comp["name"] == "Test_button"; }, pagePanel); if(button && button.length > 0){ return; } button = { xtype: "button", scope: sk, name: "Test_button", text: "Test Button", "context": [ CQ.wcm.Sidekick.PAGE ], handler: function(){ //... }, //TODO : “isable” controlled by data if existed in AEM var isable = resultFromAEM; disabled:(isable) }; pagePanel.insert(11,button); sk.actns.push(button); }, }; (function(){ var result; CQ.Ext.Ajax.request({ url: "/bin/customer", method: "GET", params : { }, success: function(response) { //TODO : TO invoke servlet but how to parse response from AEM Servlet var info = Ext.decode(response.responseText);//crash here!!!! alert(info.message); }, failure: function(response) { } }); var c = MyClientLib.ContentFinder; if( ( window.location.pathname == "/cf" ) || ( window.location.pathname.indexOf("/content") == 0)){ var SK_INTERVAL = setInterval(function(){ var sk = CQ.WCM.getSidekick(); if(sk){ clearInterval(SK_INTERVAL); c.addGsTranslate(sk); } }, 250); } })();Servlet code:
@SlingServlet(paths = "/bin/customer", methods = "POST", metatype = true) public class CustomerServlet extends SlingAllMethodsServlet { private static final long serialVersionUID = 2598426539166789515L; protected final Logger log = LoggerFactory.getLogger(this.getClass()); @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException, IOException { int result = this.getCustomerService().hasAccessToken(); JSONWriter jw = new JSONWriter(response.getWriter()); try { jw.array(); jw.object(); jw.key("result:").value(result); jw.endObject(); jw.endArray(); } catch (JSONException e) { log.error("JSON Exception:", e); } } private CustomerService getCustomerService() { BundleContext ctx = FrameworkUtil.getBundle(this.getClass()) .getBundleContext(); ServiceReference serviceReference = ctx .getServiceReference(CustomerService.class.getName()); return CustomerService.class.cast(ctx.getService(serviceReference)); } }Anyone could help see it? Thanks a lot.