Announcement Announcement Module
Collapse
No announcement yet.
Spring JPA Web App not Persisting Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JPA Web App not Persisting

    Created my own web app in an effort to teach myself Spring w/ JPA and for some reason my web app will not persist properly. I ran some tests prior to creating the web layer and they seemed to do just fine with persisting, but the web app just returns to the home page without persisting.

    Here is my controller:
    Code:
        private CustomerService cs;
        
        public ModelAndView showForm (HttpServletRequest request,
        		HttpServletResponse repsonse, BindException errors)
        		throws Exception {
        	Customer customer = new Customer();
        	return new ModelAndView("newcustomer", "customer", customer);
        }
        	
        protected Object formBackingObject(HttpServletRequest request) throws Exception{
        	
        	Customer customer = (Customer) super.formBackingObject(request);
        	customer.setAddr(new Address());    	
        	return customer;
        }
    
        public ModelAndView onSubmit(Object command) throws ServletException{
        	Customer customer = (Customer) command;
         	cs.save(customer);
        	return new ModelAndView (new RedirectView(getSuccessView()));
        }
    
    public void setCustomerService(CustomerService cs){
        	this.cs = cs;
        }
    And my JSP:
    Code:
    <form:form method="post" commandName="customer">
    	<table width="40%" bgcolor="ffffff" border="0" cellspacing="0" cellpadding="5">
    		<tr>
    			<td align="right" width="20%">First Name: </td>
    			<td width="10%">
    				<form:input path="firstName"/>
    			</td>
    			<td align="right" width="20%">Last Name: </td>
    			<td align="right" width="10%">
    				<form:input path="lastName"/>
    			</td>
    		</tr>
    	</table>
    	<br><br>
    	<table width="40%" bgcolor="ffffff" border="0" cellspacing="0" cellpadding="5">
    		<tr>
    			<td align="right" width="10%">Phone Number: </td>
    			<td width="10%">
    				<form:input path="phoneNumber"/>
    			</td>
    		</tr>
    		<tr>
    			<td align="right" width="10%">E-Mail: </td>
    			<td width="10%">
    				<form:input path="email"/>
    			</td>
    		</tr>
    	</table>
    	<input type="submit" align="left" value="Add Customer">
    	<br><br>
    	<form:errors path="*" cssClass="error"/>
    	</form:form>
    <a href="<c:url value="home.htm"/>">Home</a>
    Don't know if the error would be anywhere else so let me know if there's somewhere else I should be looking/post to check?

  • #2
    My Kreskin-ator is on the fritz so I cannot divine what

    Code:
    cs.save(customer);
    does. I think the impl might be have something to do with the problem.

    Comment

    Working...
    X