Using DictionaryConstantsWriter / DictionaryConstants

11 views
Skip to first unread message

skwe...@gmail.com

unread,
May 21, 2009, 6:36:54 PM5/21/09
to Kiyaa! GWT Toolkit
I've been looking for an easy method of serializing constants in my
JSPs to initialize my GWT app for some time now, and it looks like
Kiyaa! is the way to go for now.

After compiling the latest code I've been able to get
DictionaryConstantsWriter to produce serialized values in my JSP,
which is great. Unfortunately I've hit a wall when I actually try to
use those values.

It appears I'm missing something with the use of DictionaryConstants,
and I couldn't find any sample code to show me the way. I've got a
class StartupValues that implements DictionaryConstants, but in hosted
mode I get a message "No source code is available for type
com.habitsoft.kiyaa.util.DictionaryConstants." The interface is in
the jar file I produced. That's my first issue.

My second issue is that I'm not sure what I'm supposed to do with my
StartupValues class; it's only an implementation with no methods. How
do I access the object(s) I've written with the
DictionaryConstantsWriter? The docs aren't very clear regarding
usage, so I'm stumped.

Thanks much!

Dobes Vandermeer

unread,
May 21, 2009, 8:21:25 PM5/21/09
to kiyaa-gw...@googlegroups.com
Hi there,

The usage is very much like the Constants and Dictionary classes provided by GWT.

Define methods in the DictionaryConstants subinterface, one for each value you want to embed on the page.

To save values on the page you create your own concrete subclass on the server, for example:

MyValues mv = new MyValues() {
   String whatever() { return "whatever"; }
   Date pageServeTime() { return new Date(); }
};

And use the write to insert that into the page.

To load values from the page, use GWT.create(), like

MyValues mv = GWT.create(MyValues.class);

GWT.log(mv.whatever(), null); // access the members like this
GWT.log(mv.pageServeTime(), null); // Any serialization object can be used

I hope that helps, let me know if you have more questions.

--

Dobes Vandermeer
Director, Habitsoft Inc.
dob...@habitsoft.com
778-891-2922

Dobes Vandermeer

unread,
May 21, 2009, 8:22:28 PM5/21/09
to kiyaa-gw...@googlegroups.com
Oh, forgot to mention, make sure that your GWT module inherits the Kiyaa module with the functionality you need.  You can read about this in the GWT docs, too, but it looks something like this in your *.gwt.xml file:

    <!-- Inherit the kiyaa toolkit -->
    <inherits name='com.habitsoft.kiyaa.Kiyaa'/>

skwe...@gmail.com

unread,
May 26, 2009, 8:41:37 PM5/26/09
to Kiyaa! GWT Toolkit
Thanks for your quick responses!

The inherits wasn't the problem here... instead I forgot something
more fundamental: that I had to include the Kiyaa! .java files in the
classpath. To help things along I've created a massive jar file that
includes all the latest kiyaa code -- both .class and .java files.

Now I appear to have run into a more substantial roadblock: there
appears to be an API issue in a key class. I'm using GWT 1.5.3 which
I suspect may be the problem; perhaps Kiyaa! is compiled with 1.6.x?

In DictionaryConstantsGenerator.java you have:

String serializerClassName = baseType.getQualifiedSourceName()
+"_TypeSerializer";
TypeSerializerCreator typeSerializerCreator = new TypeSerializerCreator
(tempLogger, serializableTypeOracle, context, serializerClassName);

That doesn't compile for me; instead it wants a JClassType as the
final parameter for the constructor. I've tried:

String serializerClassName = baseType.getQualifiedSourceName()
+"_TypeSerializer";
JClassType type = getType(serializerClassName);
TypeSerializerCreator typeSerializerCreator = new TypeSerializerCreator
(tempLogger, serializableTypeOracle, context, type);

...but when I run the compiler I now get:

[java] Scanning for additional dependencies: file:/D:/project/src/
com/example/gui/client/FooModule.java
[java] Computing all possible rebind results for
'com.example.gui.client.FooStartupValues'
[java] Rebinding com.example.gui.client.FooStartupValues
[java] Invoking <generate-with
class='com.habitsoft.kiyaa.rebind.DictionaryConstantsGenerator'/>
[java] [ERROR] Failed to generate
com.example.gui.client.FooStartupValues
[java] com.google.gwt.core.ext.typeinfo.NotFoundException:
com.example.gui.client.FooStartupValues_TypeSerializer
[java] at com.google.gwt.core.ext.typeinfo.TypeOracle.getType
(TypeOracle.java:433)
[java] at com.habitsoft.kiyaa.rebind.BaseGenerator
$GeneratorInstance.getType(BaseGenerator.java:341)
[java] at
com.habitsoft.kiyaa.rebind.DictionaryConstantsGenerator
$DictionaryConstantsGeneratorInstance.generateClassBody
(DictionaryConstantsGenerator.java:128)

...and so on.

My FooStartupValues extends DictionaryConstants, has a @Dictionary
annotation, and defines several method signatures.

Any thoughts?



On May 21, 5:22 pm, Dobes Vandermeer <dob...@gmail.com> wrote:
> Oh, forgot to mention, make sure that your GWT module inherits the Kiyaa
> module with the functionality you need.  You can read about this in the GWT
> docs, too, but it looks something like this in your *.gwt.xml file:
>     <!-- Inherit the kiyaa toolkit -->
>     <inherits name='com.habitsoft.kiyaa.Kiyaa'/>
>
>
>
>
>
> On Thu, May 21, 2009 at 5:21 PM, Dobes Vandermeer <dob...@gmail.com> wrote:
> > Hi there,
> > The usage is very much like the Constants and Dictionary classes provided
> > by GWT.
>
> > Define methods in the DictionaryConstants subinterface, one for each value
> > you want to embed on the page.
>
> > To save values on the page you create your own concrete subclass on the
> > server, for example:
>
> > MyValues mv = new MyValues() {
> >    String whatever() { return "whatever"; }
> >    Date pageServeTime() { return new Date(); }
> > };
>
> > And use the write to insert that into the page.
>
> > To load values from the page, use GWT.create(), like
>
> > MyValues mv = GWT.create(MyValues.class);
>
> > GWT.log(mv.whatever(), null); // access the members like this
> > GWT.log(mv.pageServeTime(), null); // Any serialization object can be used
>
> > I hope that helps, let me know if you have more questions.
>

Dobes Vandermeer

unread,
May 26, 2009, 11:57:54 PM5/26/09
to kiyaa-gw...@googlegroups.com
Are you working with the trunk from subversion, or the last jar release?

In subversion I updated it to use the more recent GWT version 1.6.4, but I think the jar file is for 1.5.X.

Unfortunately, I don't recall exactly the changes needed to get it to work with the 1.5.X system.  I don't think there's a way to make it work with both because they changed the internal APIs I am using for the generator. :-(.

I don't think it was a huge change, though, if you view the history on that file you may be able to find the relevant change and reverse it.

I thought I had included the source in the released jar file - if not, let me know and I should probably try to make a new release.

Cheers,
Dobes

skwe...@gmail.com

unread,
May 27, 2009, 11:41:40 AM5/27/09
to Kiyaa! GWT Toolkit
I've been using the trunk code from Subversion, as the kiyaa-0.9.1.jar
release from December doesn't contain the DictionaryConstantsWriter
class mentioned in your blog post (http://www.dobesland.com/2009/02/17/
faster-gwt-startup-with-pre-loaded-objects/, found via the TechHui
post you refer to). Kiyaa-0.9.1 does have the source, just not the
source I need.

From the file history in SVN it looks like DictionaryConstantsWriter
was written in the GWT 1.6 era of code, although it compiles with GWT
1.5 fine. On the same day you created DictionaryConstantsWriter you
also amended DictionaryConstantsGenerator to support serializable
objects, so my guess is that there's no GWT 1.5 version that I can
revert to in order to get the functionality I'm looking for -- easy
serialization of GWT objects for initializing GWT modules in JSPs as
part of an internal framework.

I'll let you know if I find anything to get this working with GWT 1.5,
but we'll probably have to punt on this until we upgrade to GWT 1.6.

Thanks again for your help!
Reply all
Reply to author
Forward
0 new messages