• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Spring MVC mapping multiple objects to a model - path attribute not working as expected  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not able to map all of the nested objects to my model. The model contains composite objects, and not all values are mapping to the form fields. Curiously, this problem is sporadic, as some of the values map, while others do not. I have a hidden field (path="account.roleOption") within the userAccount.jsp (near the bottom of the form) which is mapping OK (debugged the page in FireBug) , but some of the form input field paths are not working. I will post the error, jsp, model class, and supporting nested objects code. The form displays OK, all of the c:out lines are appearing as expected, but when I click "submit" to post the form, I am receiving the error below.

error message:

[10/22/14 10:26:33:612 EDT] 0000003e ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: Uncaught exception created in one of the service methods of the servlet profile in application profilemanager-ent. Exception created : org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.NotReadablePropertyException: Invalid property 'writeNowAccess' of bean class com.summitholdings.profilemanager.user.account.UserAccount]: Bean property 'writeNowAccess' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

Model class (UserAccount.java)

package com.summitholdings.profilemanager.user.account;

import com.summitholdings.profilemanager.user.User;

public class UserAccount {


private User user;
private Account account = new Account();

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = new User(user.getId(), user.getuUID(), user.getFirstName(),
user.getMiddleInit(), user.getLastName(), user.getRoleOption(),
user.getRoleDescription(), user.getEmail(), user.getUserType(),
user.getPin());
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}

public String getFirstName() {
return user.getFirstName();
}
}

Account.java:

package com.summitholdings.profilemanager.user.account;



public class Account {


private String agency;

private String agencyRole;
public String writeNowAccess;
private String writeNowAccessInternal;
private String policy;

private String payrollNumber;

private String producer;

private String underwriter;

//private String effectiveDate;

//private String expirationDate;

private String roleOption;

/*public String getEffectiveDate() {
return effectiveDate;
}

public void setEffectiveDate(String effectiveDate) {
this.effectiveDate = effectiveDate;
}*/

public String getAgency() {
return agency;
}

public void setAgency(String agency) {
this.agency = agency;
}


public String getPolicy() {
return policy;
}

public void setPolicy(String policy) {
this.policy = policy;
}

public String getPayrollNumber() {
return payrollNumber;
}

public void setPayrollNumber(String payrollNumber) {
this.payrollNumber = payrollNumber;
}
public String getAgencyRole() {
return agencyRole;
}

public void setAgencyRole(String agencyRole) {
this.agencyRole = agencyRole;
}

/*public String getExpirationDate() {
return expirationDate;
}

public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}*/

public String getWriteNowAccess() {
return writeNowAccess;
}

public void setWriteNowAccess(String writeNowAccess) {
this.writeNowAccess = writeNowAccess;
}

public String getWriteNowAccessInternal() {
return writeNowAccessInternal;
}

public void setWriteNowAccessInternal(String writeNowAccessInternal) {
this.writeNowAccessInternal = writeNowAccessInternal;
}


public String getProducer() {
return producer;
}

public void setProducer(String producer) {
this.producer = producer;
}

public String getUnderwriter() {
return underwriter;
}

public void setUnderwriter(String underwriter) {
this.underwriter = underwriter;
}

public void setRoleOption(String roleOption) {
this.roleOption = roleOption;
}

public String getRoleOption() {
return roleOption;
}

}

User.java:

public class User {

private Long id;
private String uUID;

private String firstName;
private String middleInit;
private String lastName;

private String roleOption;
private String roleDescription;

private String email;
private String userType;

private String pin;

public User(Long id, String uUID, String firstName, String middleInit,
String lastName, String roleOption, String roleDescription,
String email, String userType, String pin) {

this.id = id;
this.uUID = uUID;
this.firstName = firstName;
this.middleInit = middleInit;
this.lastName = lastName;
this.roleOption = roleOption;
this.roleDescription = roleDescription;
this.email = email;
this.userType = userType;
this.pin = pin;
}

public User() {

}

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 getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getUserType() {
return userType;
}

public void setUserType(String userType) {
this.userType = userType;
}

public String getPin() {
return pin;
}

public void setPin(String pin) {
this.pin = pin;
}

public String getuUID() {
return uUID;
}

public void setuUID(String uUID) {
this.uUID = uUID;
}

public String getMiddleInit() {
return middleInit;
}

public void setMiddleInit(String middleInit) {
this.middleInit = middleInit;
}


public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getRoleOption() {
return roleOption;
}

public void setRoleOption(String roleOption) {
this.roleOption = roleOption;
}

public void setRoleDescription(String roleDescription) {
this.roleDescription = roleDescription;
}

public String getRoleDescription() {
return roleDescription;
}



}

userAccount.jsp

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<script type="text/javascript"
src="<c:url value="/springresources/spring/Spring.js" />">

</script>
<script type="text/javascript"
src="<c:url value="/springresources/spring/Spring-Dojo.js" />">

</script>

<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<style type="text/css">
div.hide {
display: none;
}

div.show {
display: block;
}

.error {
color: #ff0000;
}

.errorblock {
color: #000;
background-color: #ffEEEE;
border: 3px solid #ff0000;
padding: 8px;
margin: 16px;
}
</style>
<title>User Profile Manager</title>


<script type="text/javascript">
dojo.require("dijit.form.DateTextBox");
var roleId = null;
dojo.addOnLoad(function() {
roleId = dojo.byId('roleOption').value;
//connect the events to the search option drop down list
try {
dojo.byId(roleId).className = "show";
} catch (e) {
dojo.byId("noRole").className = "show";
}
alert(roleId);
});
</script>
</head>
<h1>User Profile Manager</h1>
<body>
<form:form method="POST" commandName="userAccount" modelAttribute="userAccount"
name="userAccount_form"
action="${pageContext.request.contextPath}/secured/userAccount">
<form:errors path="*" cssClass="errorblock" element="div" />
<div id="stylized" class="myform">

<table >
<tr>
<td ><label for="firstName">First name: </label>
<td><c:out value="${userAccount.user.firstName}" /></td>
</tr>
<tr>
<td ><label for="middleInit">middle: </label>
<td><c:out value="${userAccount.user.middleInit}" /></td>
</tr>
<tr>
<td ><label for="lastName">Last name: </label>
<td><c:out value="${userAccount.user.lastName}" /></td>
</tr>
<tr>
<td ><label for="email">Email: </label>
<td><c:out value="${userAccount.user.email}" /></td>
</tr>
<tr>
<td ><label for="UserType">What type of
user are you? </label></td>
<td><c:out value="${userAccount.user.roleDescription}" /></td>

</tr>
</table>
</div>

<div id="Agent" class="hide">
<table >

<!-- agency required fields -->

<tr>
<td >Agency #:<span class="small">*</span>
</td>
<td><form:input path="account.agency" maxLength="5" /></td>
</tr>

<tr>
<td ><label for="Agency Roles">Role <span
class="small">*</span>
</label></td>
<td><form:select path="account.agencyRole" id="agencyRoleOptionselect"
name="agencyRoleOptions">
<c:forEach items="${agencyRoleOptions}" var="roleVal">

<c:choose>
<c:when
test="${not empty userAccount.account.agencyRole && userAccount.account.agencyRole eq roleVal.key}">
<option value="${roleVal.key}" selected="true">${roleVal.value}</option>
</c:when>
<c:otherwise>
<option value="${roleVal.key}">${roleVal.value}</option>
</c:otherwise>
</c:choose>

</c:forEach>
</form:select></td>

</tr>
<tr>
<td >Producer #:</td>
<td><form:input path="account.producer" maxLength="5" /></td>
</tr>
<tr>
<td >Write Now Access:</td>
<td><form:radiobutton path="account.writeNowAccess" value="Y" />Yes<form:radiobutton
path="account.writeNowAccess" value="N" />No</td>
</tr>
<!-- end agency required fields -->
</table>
</div>
<div id="Insured" class="hide">
<table >

<!-- insured required fields -->
<tr>
<td >Policy #:<span class="small">*</span></td>
<td><form:input path="account.policy" maxLength="10" /></td>
</tr>

</table>
</div>
<div id="PC" class="hide">
<table >

<!-- payroll required fields -->
<tr>
<tr>
<td >Payroll #:<span class="small">*</span></td>
<td><form:input path="account.payrollNumber" maxLength="5" /></td>
</tr>

</table>
</div>
<div id="Internal" class="hide">
<table >
<tr>
<td >Write-Now Access:</td>
<td><form:radiobutton path="account.writeNowAccessInternal" value="Y" />Yes
<form:radiobutton path="account.writeNowAccessInternal" value="N" />No</td>
</tr>
<tr>
<td >Underwriter #:</td>
<td><form:input path="account.underwriter" maxLength="5" /></td>
</tr>

</table>
</div>
<div id="noRole" class="hide"></div>
<div>


<input id="submitButton" type="submit" value="Submit" />


</div>
<form:hidden path="account.roleOption" id="roleOption"
value="${userAccount.account.roleOption}" />

</form:form>
</body>
</html>




userAccount.PNG
[Thumbnail for userAccount.PNG]
 
Stuart Leonardo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured it out... My Spring Validator class has to be qualified by the model attribute nested class, (i.e, "account.invalid, when registering an error).
 
Paper beats rock. Scissors beats tiny ad.
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!