Hi David,

having worked 10 years in Java I know how to use reflection:) Sorry it
was not obvious from my post - I was just inquiring whether there's a
GWT method that could be used in client code - some method that
escaped my search.

Anyway, I've solved this problem yesterday by writing a simple
generator that generates typed adapters for my data classes, such a
generated adapter looks like:

class Adapter<Myclass> {

  setTypedObj(Myclass obj) { ... }

  setValue(String fieldName, Object value) {
    if("someProp".equals(fieldName))
       obj.setSomeProp(value);
    else ...
  }

  //similar for getValue
}

That way I can bridge my typed (my GWT code) and untyped (I use GXT
which uses ModelData dynamic bean) operations and still benefit from
rigorous typing.

George


On Jul 9, 11:58 am, David Goodenough <[email protected]>
wrote:
> You can do it in real java, but as reflection is not supported in GWT it would
> not work in GWT.
>
> In real java you would say:-
>
> Test test = new Test();
> Test.getClass().getField("value").set(test,"some value");
>
> Note that if value is a private or protected field then you need to use
> getDeclaredField not getField.
>
> David
>
> On Wednesday 08 July 2009, george9 wrote:
>
> > When you have a typed class, say
>
> > class Test {
> >     String value;
> > }
>
> > is it somehow possible to set field 'value' without a static reference
> > in the code?
> > I'm looking for an equivalent to JavaScript's:
>
> > var Test = { };
> > Test["value"] = "some value";
>
> > JSNI can access a java field via the "[instance-exp...@class-
> > name::field-name" notation, but that looks like a compile time thing.
>
> \

--~--~---------~--~----~------------~-------~--~----~
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