没有getter方法可用于名称下bean的属性

时间:2013-09-24 15:13:03

标签: java jsp struts-1

Struts(1.38)noob,我收到以下错误: 对于名称为hsForm的bean,没有可用于属性hs.hasRelationshipToTeam的getter方法。 有人告诉我在HSDivForm中创建一个getHs和setHs方法,但问题是什么?或者我该怎么做呢?

我的豆子:

public class HS extends Entry implements Serializable,Cloneable  {
  private Boolean hasRelationshipToTeam = false;

  public boolean isHasRelationshipToTeam() 
  { return hasRelationshipToTeam; }

  public void setHasRelationshipToTeam(boolean hasRelationshipToTeam) 
  { this.hasRelationshipToTeam = hasRelationshipToTeam; }
}

我的表格:

import my.bean.HS;

public class HSForm extends ActionForm
{
  private HS hs = new HS();

  public HSForm() 
  { super(); }
}

我的jsp:

<html:form styleId="HSDivForm" action="/disclosure/hsAction" >
<table>
  <tr id = "q-rel">
    <td colspan="2" align="center">
      <br />
      Is there a team relationship?
      <br />
      Yes<html:radio property="hs.hasRelationshipToTeam" value="yes" />    
      No<html:radio property="hs.hasRelationshipToTeam" value="no" />
    </td>
  </tr>
</table>
</html>

2 个答案:

答案 0 :(得分:2)

那是因为你的属性类型:

private Boolean hasRelationshipToTeam = false;

将您的属性声明为Boolean时,Introspector并未将其视为原始boolean,因此它需要getXXXsetXXX。< / p>

如果您的属性是boolean原始类型,则Introspector需要isXXXgetXXX,与setXXX方法捆绑在一起。

getXXXisXXX是您的getter方法,而setXXX是您的setter方法。

我希望这会有所帮助。

答案 1 :(得分:0)

将你的吸气剂改为

 public boolean isHasRelationshipToTeam() 
  { 
   return hasRelationshipToTeam;
  }

以前是

isHasRelationshipToTeamy()   y is there in the end<----

我也怀疑你的宣言

  private Boolean hasRelationshipToTeam = false;  

将其更改为

  private boolean hasRelationshipToTeam = false; //boolean is primitive here

对于普通的java类,您可以为其指定任何名称,并返回任何variable

但bean有标准格式,你无法改变它们。