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>
4

2 回答 2

2

那是因为您在属性中的类型:

private Boolean hasRelationshipToTeam = false;

将您的属性声明为Boolean时,Introspector不会将其视为原始属性,boolean因此它需要 agetXXXsetXXX

如果您的属性是boolean原始类型,则Introspector期望 aisXXX或与方法getXXX捆绑在一起setXXX

getXXXandisXXX是你的 getter 方法,而 thesetXXX是你的 setter 方法。

我希望这有帮助。

于 2013-11-07T23:34:21.460 回答
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 有一个标准格式,你不能改变它们。

于 2013-09-24T15:18:07.857 回答