• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Binding a single spring form to multiple POJO Class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I tried to bind the spring form to multiple POJO class, but i could not successfully do that and i am getting the following error.
I am in need of any one who can help me to solve this issue.
Here by i am adding the Spring Form, POJO Classes and the Controller class.



org.apache.jasper.JasperException: An exception occurred processing JSP page /view/createaccount.jsp at line 59

56: </tr>
57:
58: <tr>
59: <td>Card No:<FONT color="red"><form:errors
60: path="cardNo" /></FONT></td>
61:
62:


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

org.springframework.beans.NotReadablePropertyException: Invalid property 'cardNo' of bean class [com.mbank.entity.AccountDetails]: Bean property 'cardNo' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:707)
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:699)
org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:98)
org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:224)
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:120)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
org.springframework.web.servlet.tags.form.ErrorsTag.shouldRender(ErrorsTag.java:140)
org.springframework.web.servlet.tags.form.AbstractHtmlElementBodyTag.writeTagContent(AbstractHtmlElementBodyTag.java:47)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
org.apache.jsp.view.createaccount_jsp._jspService(createaccount_jsp.java:280)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)



Spring Form
=========

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Mobile Banking - Creating an online account</title>
</head>
<body>
<center>
<h2>Account Creation Form</h2>
<form:form action="createaccount.html" commandName="accountDetails">
<table>
<tr>
<td>First Name:<FONT color="red"><form:errors
path="firstName" /></FONT></td>


<td><form:input path="firstName" /></td>
</tr>
<tr>
<td>Last Name:<FONT color="red"><form:errors
path="lastName" /></FONT></td>

<td><form:input path="lastName" /></td>

</tr>
<tr>
<td>Account Type:<FONT color="red"><form:errors
path="accountType" /></FONT></td>

<td><form:input path="accountType" /></td>
</tr>


<tr>
<td>Mobile No:<FONT color="red"><form:errors
path="mobileNo" /></FONT></td>

<td><form:input path="mobileNo" /></td>
</tr>

<tr>
<td>Phone No:<FONT color="red"><form:errors
path="phoneNo" /></FONT></td>

<td><form:input path="phoneNo" /></td>
</tr>

<tr>
<td>Email:<FONT color="red"><form:errors
path="email" /></FONT></td>

<td><form:input path="email" /></td>
</tr>

<tr>
<td>Card No:<FONT color="red"><form:errors
path="cardNo" /></FONT></td>


<td><form:input path="cardNo" /></td>
</tr>
<tr>
<td>Pin:<FONT color="red"><form:errors
path="pin" /></FONT></td>

<td><form:input path="pin" /></td>
</tr>

<tr>
<td>Address Line 1:<FONT color="red"><form:errors
path="adressLine1" /></FONT></td>


<td><form:input path="adressLine1" /></td>
</tr>
<tr>
<td>Address Line 1:<FONT color="red"><form:errors
path="adressLine2" /></FONT></td>

<td><form:input path="adressLine2" /></td>
</tr>

<tr>
<td>City:<FONT color="red"><form:errors
path="city" /></FONT></td>

<td><form:input path="city" /></td>
</tr>

<tr>
<td>State:<FONT color="red"><form:errors
path="state" /></FONT></td>

<td><form:input path="state" /></td>
</tr>

<tr>
<td>Country:<FONT color="red"><form:errors
path="country" /></FONT></td>

<td><form:input path="country" /></td>
</tr>

<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
</center>
</body>
</html>


POJO Classes
=============

public class AccountDetails {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int accountId;
private String firstName;
private String lastName;
private String currentBalance;
private String accountType;
private String mobileNo;
private String phoneNo;
private String email;


@OneToOne
@JoinColumn(name="addressId")
private Address address;

@OneToOne(mappedBy="accountDetails")
private MasterLogin masterLogin;



public MasterLogin getMasterLogin() {
return masterLogin;
}
public void setMasterLogin(MasterLogin masterLogin) {
this.masterLogin = masterLogin;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public String getMobileNo() {
return mobileNo;
}
public void setMobileNo(String mobileNo) {
this.mobileNo = mobileNo;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getAccountId() {
return accountId;
}
public void setAccountId(int accountId) {
this.accountId = accountId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getCurrentBalance() {
return currentBalance;
}
public void setCurrentBalance(String currentBalance) {
this.currentBalance = currentBalance;
}
public String getAccountType() {
return accountType;
}
public void setAccountType(String accountType) {
this.accountType = accountType;
}

}







public class Address {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int addressId;
private String adressLine1;
private String adressLine2;
private String city;
private String state;
private String country;
public int getAddressId() {
return addressId;
}
public void setAddressId(int addressId) {
this.addressId = addressId;
}
public String getAdressLine1() {
return adressLine1;
}
public void setAdressLine1(String adressLine1) {
this.adressLine1 = adressLine1;
}
public String getAdressLine2() {
return adressLine2;
}
public void setAdressLine2(String adressLine2) {
this.adressLine2 = adressLine2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}

}



public class MasterLogin {
@Id
@NotEmpty(message="Card No Cannot be empty")
@NumberFormat(style = Style.NUMBER)
private Integer cardNo;

private String loginName;

@NotEmpty(message="Pin Cannot be empty")
@Size(min = 4, max = 4, message = "Pin must be of 4 Characters.")
private String pin;

@OneToOne
@JoinColumn(name="accountId")
private AccountDetails accountDetails;

@OneToMany(mappedBy="masterLogin")
private Collection<TransactionHistory> transactionHistory=new ArrayList<TransactionHistory>();


public AccountDetails getAccountDetails() {
return accountDetails;
}
public void setAccountDetails(AccountDetails accountDetails) {
this.accountDetails = accountDetails;
}
public Collection<TransactionHistory> getTransactionHistory() {
return transactionHistory;
}
public void setTransactionHistory(
Collection<TransactionHistory> transactionHistory) {
this.transactionHistory = transactionHistory;
}
public Integer getCardNo() {
return cardNo;
}
public void setCardNo(Integer cardNo) {
this.cardNo = cardNo;
}
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin = pin;
}


}


Controller Class
=================

public class MasterLogin {
@Id
@NotEmpty(message="Card No Cannot be empty")
@NumberFormat(style = Style.NUMBER)
private Integer cardNo;

private String loginName;

@NotEmpty(message="Pin Cannot be empty")
@Size(min = 4, max = 4, message = "Pin must be of 4 Characters.")
private String pin;

@OneToOne
@JoinColumn(name="accountId")
private AccountDetails accountDetails;

@OneToMany(mappedBy="masterLogin")
private Collection<TransactionHistory> transactionHistory=new ArrayList<TransactionHistory>();


public AccountDetails getAccountDetails() {
return accountDetails;
}
public void setAccountDetails(AccountDetails accountDetails) {
this.accountDetails = accountDetails;
}
public Collection<TransactionHistory> getTransactionHistory() {
return transactionHistory;
}
public void setTransactionHistory(
Collection<TransactionHistory> transactionHistory) {
this.transactionHistory = transactionHistory;
}
public Integer getCardNo() {
return cardNo;
}
public void setCardNo(Integer cardNo) {
this.cardNo = cardNo;
}
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin = pin;
}


}


Thanks & Regards
Suresh

 
Ranch Hand
Posts: 93
Python Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The log itself says the error,



Check whether the com.mbank.entity.AccountDetails has cardNo property. If it exists, check the getters and setters.


Note: Please post the code in code tags
 
reply
    Bookmark Topic Watch Topic
  • New Topic