1) I hope you are using in your controller @SessionAttributes("newSale")
I had forgotten this, but adding doesn't help as the page can't even load on the 1st GET
2) Post both POJO classes
Code:
//Customer Entity
@Entity
@Table( name="Customer")
public class Customer extends DbAssignedIdEntity implements DateEntered, Listable {
@Column( name="DATE_ENTERED" )
private Date dateEntered;
@Column( name="FIRST_NAME" )
private String firstName;
@Column( name="LAST_NAME" )
private String lastName;
@Column( name="TITLE" )
private String title;
@Column( name="COMPANY" )
private String company;
@Column( name="EMAIL", unique=true )
private String email;
@Column( name="PHONE_NUMBER", length=12 )
private String phone;
@Column( name="REGISTERED" )
private boolean registered;
@Column( name="HAS_SUPPORT" )
private boolean supportActive;
@Column( name="ADDRESS_1")
private String address1;
@Column( name="ADDRESS_2")
private String address2;
@Column( name="COUNTRY" )
private String country;
@Column( name="CITY" )
private String city;
@Column( name="STATE" )
private String state;
@Column( name="ZIP_CODE" )
private String zipCode;
@Column( name="INDUSTRY" )
private String industry;
@Column( name="NUMBER_ASSETS" )
private Integer numberAssets;
@Column( name="REGULATED" )
private boolean regulated = false;
@Override
public Date getDateEntered() {
return dateEntered;
}
@Override
public void setDateEntered(Date dateEntered) {
this.dateEntered = dateEntered;
}
@Override
public SelectValue getSelectValue() {
return new SelectValue( lastName + ", " + firstName + " (" + company + ")", id );
}
}
//New Sales modeled attributed that contains a customer
public class NewSale {
@Min( value=1, message="You must select a Product")
private Long productId;
private boolean newCust;
private Customer customer;
@Min( value=1, message="You must specify a Sales Rep")
private Long repId;
public NewSale() {}
public NewSale( Customer customer ) {
newCust = customer == null || customer.getId() == null;
this.customer = customer;
}
//Add get / set methods for testing
public Long getProductId() {
return productId;
}
public void setProductId( Long id ) {
productId = id;
}
public boolean isNewCust() {
return newCust;
}
public void setNewCust( boolean newCust ) {
this.newCust = newCust;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer( Customer customer) {
this.customer = customer;
}
public Long getRepId() {
return repId;
}
public void setRepId(Long repId) {
this.repId = repId;
}
}
3) Are you sure is always executed the line model.addAttribute( "newSale", new NewSale( cust )?, you have a conditional block
My jsp checks for the existence of the objects, see below...
Post your jsp code, a missing detail is there
This is the the contents of the page body. The ${saleReps} & ${products} lists are loaded via @ModelAttribute methods in the controller.
Note: I've also tried with Customer (capital 'C'), just to see, but that doesn't work either.
Code:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<c:if test="${not empty newSale}">
<form:form modelAttribute="newSale" >
<c:if test="${not empty error}">
<p class="error" >${error}</p><br>
</c:if>
<form:hidden path="customer.id"/>
<form:hidden path="newCust"/>
<form:hidden path="customer.registered" value="true" />
<form:label path="customer.company" for="customer.company">Company Name</form:label>
<form:input path="customer.company" /><form:errors path="customer.company" class="error" /><br>
<form:label path="customer.industry" for="customer.industry">Industry</form:label>
<form:select path="customer.industry" >
<form:option label="-- Select an Industry -- " value="0" />
<form:options items="${industries}" itemLabel="selectLabel" itemValue="selectValue"/>
</form:select><br>
<form:label path="customer.firstName" for="customer.firstName">First Name</form:label>
<form:input path="customer.firstName" /><form:errors path="customer.firstName" class="error" /><br><br>
<form:label path="customer.lastName" for="customer.lastName">Last Name</form:label>
<form:input path="customer.lastName" /><form:errors path="customer.lastName" class="error" /><br>
<form:label path="customer.title" for="customer.title">Title</form:label>
<form:input path="customer.title" /><br>
<form:label path="customer.email" for="customer.email">Email</form:label>
<form:input path="customer.email" /><form:errors path="customer.email" class="error" /><br>
<form:label path="customer.phone" for="customer.phone">phone</form:label>
<form:input path="customer.phone" /><br>
<form:label path="customer.address1" for="customer.address1">Address Line 1</form:label>
<form:input path="customer.address1" /><br>
<form:label path="customer.address2" for="customer.address1">Address Line 2</form:label>
<form:input path="customer.address2" /><br>
<form:label path="customer.city" for="customer.city">City</form:label>
<form:input path="customer.city" />
<form:label path="customer.state" for="customer.state">State</form:label>
<form:input path="customer.state" />
<form:label path="customer.zipCode" for="customer.zipCode" onkeypress="return numbersonly( this, event)" onpaste="return stopPaste( event )">Zip Code</form:label>
<form:input path="customer.zipCode" /><br>
<form:label path="repId" for="repId">Sales Rep</form:label>
<form:select path="repId" >
<form:option label="-- Select Sales Rep -- " value="0" />
<form:options items="${salesReps}" itemLabel="selectLabel" itemValue="selectValue"/>
</form:select><form:errors path="repId" class="error" /><br>
<form:label path="productId" for="productId">Product</form:label>
<form:select path="productId" >
<form:option label="--- Select Product ---" value="0" />
<form:options items="${products}" itemLabel="selectLabel" itemValue="selectValue"/>
</form:select><form:errors path="productId" class="error" /><br>
<input type="submit" name="insert" value="Process"/>
</form:form>
</c:if>
All my other pages render fine. Changing from direct field access to bean property access lets the page render, but the data isnt saved to the newSales.customer because of the lack of getters and setters. I did test adding get / set methods for a few customer properties and it work, but this is not the path I wish to take if it can be avoided.
Thanks for all the help