2013-09-27 38 views
0

這是我的這會導致錯誤既不BindingResult也不對bean名稱純目標對象「bankDetails [0]」可作爲請求屬性誤差在Spring MVC

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

這是我的控制器代碼

JSP代碼段
@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 

回答

0

首先,bankDetails不是數組,所以通過是作爲數組的形式豆將不能正常工作的發生同樣的情況。我會使用標準的JSTL for-each循環遍歷bankDetails ArrayList。此外,您並未將bankDetails傳遞給JSP,而是將對象details。同時檢查您是否擁有BankDetails bean中的bankDetails的getter。

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

編輯:看看你返回的是ModelAndView參數。你已經指定了bean的名字應該是'command'。將其更改爲字符串或名稱的「詳細信息」或您在視圖JSP中使用的bean。

+0

我不必打印出值。我必須綁定每個EntityBankDetail對象的屬性才能形成。 –

+0

我知道,但是您正在以數組的形式訪問bankDetails;不是ArrayList。 – blackpanther

+0

我可以隨時訪問它,我有一個工作代碼,說明了這一點。請檢查我的編輯了。 –

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結構同樣重要。

相關問題