(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<java.lang.String> keySet() {
        return dictionary.keySet();
    }

    public java.lang.String toString() {
        return dictionary.toString();
    }

    public java.util.Collection<java.lang.String> 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to