开发者

Picky on Getter/Setter name? JSF/Jboss Seam

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: mappingUI开发者_如何学运维D   

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


  • 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜