Picky on Getter/Setter name? JSF/Jboss Seam

2019-09-08 06:29发布

问题:

I'm working on a JBoss seam application (JSF 1.1 and MyFaces Tomahawk) which runs on tomcat 5.0.28.

What is bugging me is that at times when i create a variable and the setter and getter for it they don't get picked up resutling in me getting errors like:

 javax.faces.el.PropertyNotFoundException: Bean: com.sportsMed.Util , property: mappingUID   

I have to try and change the Setter/Getter name repeatedly and test until it passes through without errors and this can be going through 5-6 different names and becomes such a waste of time.

Am i doing something wrong? Just 10 minutes ago i had to change:

  private String UserName;
  public void setUserName(String s)...
  public String getUserName()....

that didn't work resulting in Property not found so i changed the above to:

  private String user_Name;
  public void setuser_Name(String s)...
  public String getuser_Name()....

Nope and finally tried:

  private String nUser;
  public void setnUser(String s)...
  public String getnUser()....

Somehow that works fine! and as mentioned at times it won't work until 5-6 name changes! Can someone tell me what I'm doing wrong or why its happening. Thanks

回答1:

  • field must be lower-case, without underscores
  • setter must be set + capitalized field (same for getter)

So:

private String userName;
public void setUserName(..);
public String getUserName(..);

Reference: javabeans spec, java naming conventions

Using an IDE (Eclipse, NetBeans, IntelliJ) to generate the setters and getters would make things easier.



标签: java jsf seam