[jboss-user] [JBoss Seam] - non-void property setters

roger_goldman2000 do-not-reply at jboss.com
Wed Oct 10 20:29:47 EDT 2007


Is there any particular reason why the property setters are restricted to having a 'void' return type?  

It is sometimes convenient to have a class like:

  | @Name(user)
  | public class User {
  |   private String username;
  |   private String password;
  | 
  |   public String getUsername() { return this.username; }
  |   public User setUsername( String u ) { this.username = u; return this; }
  |   public String getPassword() { return this.password; }
  |   public User setPassword( String p ) { this.password = p; return this; }
  | }
  | 
so that you can then do:

  |   ...
  |   User user = new User().setUsername("rag").setPassword("s3cr3t");
  |   ...
  | 

Unfortunately, when we try to reference #{user.username}, we get
value="#{user.username}": Property 'username' not writable on type java.lang.String.

Thoughts?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4093801#4093801

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4093801



More information about the jboss-user mailing list