Picky on Getter/Setter name? JSF/Jboss Seam

这一生的挚爱 提交于 2019-12-12 02:27:28

问题


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.



来源:https://stackoverflow.com/questions/7702145/picky-on-getter-setter-name-jsf-jboss-seam

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!