Re: Dictionary on demand
Thank you for this sample, very interesting. Just for information, where do you instanciate DictionaryOnDemand? In my case, I create it in the onModuleLoad method, because I need it in view initialization, but the problem is that : because of deffered command (but needed...), dictionnary is binded after view init Any idea? Thank again, -- ECH On 2 déc, 11:13, obesga wrote: > ... maybe it's not .js file loaded when you create the dictionary. > ( I thougth > > As in my test the behaviour works well, I thougth that when you do the > getJsFile() method, the file was loaded into the browser ( even if the > browser and the execution of js scripts must wait to the complete load > of the file ) > > But on production deployment sometimes I got the same exception; which > I relsolved like this > > public DictionaryOnDemand(String url,final String dname){ > getJsFile(url); > DeferredCommand.addCommand(new Command(){ > public void execute() { > dictionary = Dictionary.getDictionary(dname); > } > }); > } > > private native void getJsFile(String url) /*- { > var fileref = $doc.createElement('script'); > fileref.setAttribute("type","text/javascript"); > fileref.setAttribute("src", url); > $doc.getElementsByTagName("head")[0].appendChild(fileref) > } -*/; > > See if this help you > > Oskar > > On 1 dic, 15:27, bennyb wrote: > > > I am still getting the errors: > > > [ERROR] Uncaught exception escaped > > java.util.MissingResourceException: 'example' is not a JavaScript > > object and cannot be used as a Dictionary > > at com.google.gwt.i18n.client.Dictionary.resourceErrorBadType > > (Dictionary.java:100) > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Dictionary on demand
... maybe it's not .js file loaded when you create the dictionary. ( I thougth As in my test the behaviour works well, I thougth that when you do the getJsFile() method, the file was loaded into the browser ( even if the browser and the execution of js scripts must wait to the complete load of the file ) But on production deployment sometimes I got the same exception; which I relsolved like this public DictionaryOnDemand(String url,final String dname){ getJsFile(url); DeferredCommand.addCommand(new Command(){ public void execute() { dictionary = Dictionary.getDictionary(dname); } }); } private native void getJsFile(String url) /*- { var fileref = $doc.createElement('script'); fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", url); $doc.getElementsByTagName("head")[0].appendChild(fileref) } -*/; See if this help you Oskar On 1 dic, 15:27, bennyb <[EMAIL PROTECTED]> wrote: > I am still getting the errors: > > [ERROR] Uncaught exception escaped > java.util.MissingResourceException: 'example' is not a JavaScript > object and cannot be used as a Dictionary > at com.google.gwt.i18n.client.Dictionary.resourceErrorBadType > (Dictionary.java:100) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Dictionary on demand
I am still getting the errors: [ERROR] Uncaught exception escaped java.util.MissingResourceException: 'example' is not a JavaScript object and cannot be used as a Dictionary at com.google.gwt.i18n.client.Dictionary.resourceErrorBadType (Dictionary.java:100) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Dictionary on demand
IMPORTANT, THE PREVIOUS NATIVE METHOD IS NOT CORRECT The nativ method must be private static native void getJsFile() /*-{ var fileref = $doc.createElement('script'); fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src","operadores/operadores.js"); $doc.getElementsByTagName("head")[0].appendChild(fileref) }-*/; just to load correctly the file... Excurse On 30 nov, 17:45, obesga <[EMAIL PROTECTED]> wrote: > I really don't assume this, it's the way I'm going to use it. > > In my application, the file is generated by a servlet that writes a > POJO into the file, as shown > > response.setContentType("text/javascript"); > response.setHeader("Expires", "0"); > response.setHeader("Cache-Control", "must-revalidate, post- > check=0, pre-check=0"); > response.setHeader("Pragma", "public"); > StringBuilder sb = new StringBuilder(); > sb.append("var mypojovar = {"); > for (MyPojo myPojo : database.getMyPojoList()) > sb.append("\n\t").append(myPojo.getId()).append(": > \"").append(myPojo.getName()).append("\","); > sb.deleteCharAt(sb.length() - 1); > sb.append("\n};"); > response.getWriter().print(sb.toString()); > response.getOutputStream().flush(); > response.getOutputStream().close(); > > BTW, the mehod is easyly modificable to accetp different file and > variable/dictionary name > > public DictionaryOnDemand(String url, String dname){ > getJsFile(url); > dictionary = Dictionary.getDictionary(dname); > } > > private native void getJsFile(String url) /*- { > var fileref = $doc.createElement('script'); > fileref.setAttribute("type","text/javascript"); > fileref.setAttribute("src", url); > } -*/; > > The key in this behaviour is the 'text/javascript' content type of the > file > > Oskar > > On 30 nov, 15:04, bennyb <[EMAIL PROTECTED]> wrote: > > > Why do you assume every javascript file would have a ".js" extension? > > Some files could be dynamically generated depending on querystring > > parameters so we might request ".php" or ".asp" files --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Dictionary on demand
I really don't assume this, it's the way I'm going to use it. In my application, the file is generated by a servlet that writes a POJO into the file, as shown response.setContentType("text/javascript"); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post- check=0, pre-check=0"); response.setHeader("Pragma", "public"); StringBuilder sb = new StringBuilder(); sb.append("var mypojovar = {"); for (MyPojo myPojo : database.getMyPojoList()) sb.append("\n\t").append(myPojo.getId()).append(": \"").append(myPojo.getName()).append("\","); sb.deleteCharAt(sb.length() - 1); sb.append("\n};"); response.getWriter().print(sb.toString()); response.getOutputStream().flush(); response.getOutputStream().close(); BTW, the mehod is easyly modificable to accetp different file and variable/dictionary name public DictionaryOnDemand(String url, String dname){ getJsFile(url); dictionary = Dictionary.getDictionary(dname); } private native void getJsFile(String url) /*- { var fileref = $doc.createElement('script'); fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", url); } -*/; The key in this behaviour is the 'text/javascript' content type of the file Oskar On 30 nov, 15:04, bennyb <[EMAIL PROTECTED]> wrote: > Why do you assume every javascript file would have a ".js" extension? > Some files could be dynamically generated depending on querystring > parameters so we might request ".php" or ".asp" files --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Dictionary on demand
Why do you assume every javascript file would have a ".js" extension? Some files could be dynamically generated depending on querystring parameters so we might request ".php" or ".asp" files --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Dictionary on demand
(uf, a lot of time without posting here...) I've done a class to load a dictionary on demand, by loading a javascript file dinamicaly. Contructor uses a String parameter - sname - which will be the Dictionary name. The js file must be named like 'sname.js' and contain a varible like 'var sname' Aside from this, it works as a normal Dictionary I post it here, so you can comment it (please if you see any improvent or correction) - or use it if you like and need the code Oskar /*java file [DictionaryOnDemand.java ] */ package myutils; import com.google.gwt.i18n.client.Dictionary; public class DictionaryOnDemand { private Dictionary dictionary; public DictionaryOnDemand(String sname){ getJsFile(sname); dictionary = Dictionary.getDictionary(sname); } private native void getJsFile(String sname) /*- { var filename = sname + ".js"; var fileref = $doc.createElement('script'); fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", filename); } -*/; public java.lang.String get(java.lang.String s){ return dictionary.get(s); } public java.util.Set keySet() { return dictionary.keySet(); } public java.lang.String toString() { return dictionary.toString(); } public java.util.Collection values() { return dictionary.values(); } } /**example of use / DictionaryOnDemand dod = new DictionaryOnDemand("example"); Window.alert( dod.get("myExample") ); /*js file of example [example.js] / var example = { myExample:"Hello GWorldT" }; --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---