在Getter/Setter名称上挑剔? JSF/Jboss接缝 [英] Picky on Getter/Setter name? JSF/Jboss Seam

查看:68
本文介绍了在Getter/Setter名称上挑剔? JSF/Jboss接缝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个运行在tomcat 5.0.28上的JBoss接缝应用程序(JSF 1.1和MyFaces Tomahawk).

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

让我烦恼的是,有时我创建一个变量以及它的setter和getter时,它们不会被重新整理以获取诸如以下错误:

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   

我必须尝试反复更改Setter/Getter的名称,并进行测试,直到无误通过为止,这可能要使用5-6个不同的名称,并且会浪费时间.

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.

我做错什么了吗?就在10分钟前,我不得不更改:

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

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

那不起作用导致找不到Property,所​​以我将以上内容更改为:

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()....

不,最后尝试:

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

以某种方式可以正常工作!而且有时会提到,直到5-6名更改,它才起作用!有人可以告诉我我在做什么错或为什么会这样.谢谢

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

推荐答案

  • 字段必须为小写字母,没有下划线
  • 设置者必须为set +大写字母的字段(与getter相同)
    • field must be lower-case, without underscores
    • setter must be set + capitalized field (same for getter)
    • 所以:

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

      参考: javabeans规范 java命名约定

      使用IDE(Eclipse,NetBeans,IntelliJ)生成设置器和获取器将使事情变得更容易.

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

      这篇关于在Getter/Setter名称上挑剔? JSF/Jboss接缝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆