0

这是我的 JSP 代码片段,它会导致错误

<form:select path="bankDetails[0].applicantType">
    <form:option value="Applicant">Applicant</form:option>
    <form:option value="Co-Applicant 1">Co-Applicant 1</form:option>
    <form:option value="Co-Applicant 2">Co-Applicant 2</form:option>
    <form:option value="Co-Applicant 3">Co-Applicant 3</form:option>
    <form:option value="Guarantor 1">Guarantor 1</form:option>
    <form:option value="Guarantor 2">Guarantor 2</form:option>
    <form:option value="Guarantor 3">Guarantor 3</form:option>
 </form:select>

这是我的控制器代码

   @RequestMapping(value = "enterBankDetails.htm", method = RequestMethod.GET)
   public ModelAndView enterBankDetails() {
      functionName = "enterBankDetails";
      logger.info("In "+className+" - "+functionName+" ");
      BankDetails details = new BankDetails();
      ArrayList<EntityBankDetail> entitityBankDetails = new ArrayList<EntityBankDetail>();
      for(int i = 0 ; i < 4 ;i++){
            EntityBankDetail entityBankDetail = new EntityBankDetail();
            entitityBankDetails.add(entityBankDetail);
      }
      details.setBankDetails(entitityBankDetails);
      return new ModelAndView("bankDetails/bankDetails", "command",details);
   }

这是bean代码

public class BankDetails {
    private ArrayList<EntityBankDetail> bankDetails;
    private String[] entities;
    private int noOfBankDetails;
     private String test;
      //getter and setter methods
}

public class EntityBankDetail {
    private String nameOfBank;
    private String EMIforProposedLoan;
    private String nameOfBranch;
    private String city;
    private String accountType;
    private String accountNumber;
    private String applicantType;
           //getter and setter methods  
}

我收到以下错误

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'bankDetails[0]' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)

请帮忙。我不知道我在做什么错?

编辑:当我将它绑定到测试时也会发生同样的情况

<form:select path="test">
    <form:option value="Applicant">Applicant</form:option>
    <form:option value="Co-Applicant 1">Co-Applicant 1</form:option>
    <form:option value="Co-Applicant 2">Co-Applicant 2</form:option>
    <form:option value="Co-Applicant 3">Co-Applicant 3</form:option>
    <form:option value="Guarantor 1">Guarantor 1</form:option>
    <form:option value="Guarantor 2">Guarantor 2</form:option>
    <form:option value="Guarantor 3">Guarantor 3</form:option>
    </form:select> 

Neither BindingResult nor plain target object for bean name 'test' available as request attribute
4

2 回答 2

0

这是我的错误。我已经包括

 <form:select path="test">
    <form:option value="Applicant">Applicant</form:option>
    <form:option value="Co-Applicant 1">Co-Applicant 1</form:option>
    <form:option value="Co-Applicant 2">Co-Applicant 2</form:option>
    <form:option value="Co-Applicant 3">Co-Applicant 3</form:option>
    <form:option value="Guarantor 1">Guarantor 1</form:option>
    <form:option value="Guarantor 2">Guarantor 2</form:option>
    <form:option value="Guarantor 3">Guarantor 3</form:option>
    </form:select> 

在我的<form:form> </form:form>标签之外。所以现在我知道如果我遇到这种错误,检查 jsp 结构同样重要。

于 2013-09-27T07:36:41.417 回答
0

首先,bankDetailsis 不是数组,因此将 is 作为数组传递给表单 bean 将无法正常工作。我会使用标准的 JSTL for-each 循环来遍历bankDetails ArrayList. 此外,您不是将 bankDetails 传递给 JSP,而是传递 object details。还要检查 BankDetails bean 中是否有一个获取 bankDetails 的方法。

<c:forEach items="details.bankDetails" var="bankDetail">
    ...
</c:forEach>

编辑:看看你作为 ModelAndView 参数返回的内容。您已指定 bean 名称应为“命令”。将其更改为字符串或名称“详细信息”或您在视图 JSP 中使用的 bean。

于 2013-09-27T06:49:44.747 回答