Sunday, June 22, 2014

GWT RequestFactory: IllegalArgumentException for setter only fields

Why is it mandatory to have both getters and setters for a field in RF Proxy interfaces? For some fields (like plain text password), you want setters only.
e.g.

    @ProxyFor(value = User.class)
   
public interface UserProxy extends ValueProxy {
       
void setPassword(String password);
   
}


User class has both getters and setters.

   
public class User implements Serializable {
   
   
private String password;
   
   
public String getPassword() {
       
return password;
   
}
   
   
public void setPassword(String password) {
       
this.password = password;
   
}



When I set the password on proxy, I get an IllegalArgumentException:

    UserProxy user = userRequest.create(UserProxy.class);
    user
.setPassword("abc");



Above code results in following error:
java.lang.IllegalArgumentException: password
    at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl.doCoderFor(AutoBeanCodexImpl.java:525)
    at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.setProperty(AbstractAutoBean.java:276)
...
...

This error goes away if I add a 'getPassword()' method in UserProxy interface but that defeats the purpose. Any help is appreciated. 

Thanks,
Arpit

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment