rax313
rax313

Reputation: 88

bind form to an object in SPRING 3.0

Hi I am following Passing parameters from JSP to Controller in Spring MVC obviously I am missing something because I am getting

javax.el.PropertyNotFoundException: Property 'Title' not found on type com.outbottle.hellospring.entities.Movie

Any Idea as to what I am missing?

my Controller:

package com.outbottle.hellospring.controllers;

import com.outbottle.hellospring.entities.Movie;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;



@Controller
@SessionAttributes("Movie")

public class FormPractice{

//display the form
@RequestMapping(value="/form", method= RequestMethod.GET)
public String form(ModelMap map) {

    map.addAttribute("Movie", new Movie());
    //return new ModelAndView("form", "movie", new Movie());  
    return "form";

}


// Process the form

@RequestMapping(value="/showMovies", method = RequestMethod.POST)
public String processMovieRegistration(@ModelAttribute("Movie") Movie moviedata,
                                       BindingResult result,                                           
                                       HttpServletRequest request,
                                       Map<String, Object> map){


    //System.out.print(moviedata.Title);
    map.put("moviedata", moviedata);
    //map.addAttribute("movie", moviedata);

    map.put("date", request.getParameter("date"));

    return "showMovies";
}



   public Movie formBackingObject() {
     return new Movie();
   }

}

My Object

package com.outbottle.hellospring.entities;

import java.util.Date;




public class Movie {

    private String Title;
    private Date  ReleaseDate;



    /**
     * @return the ReleaseDate
     */
    public Date getReleaseDate() {
        return ReleaseDate;
    }

    /**
     * @param ReleaseDate the ReleaseDate to set
     */
    public void setReleaseDate(Date ReleaseDate) {
        this.ReleaseDate = ReleaseDate;
    }

    /**
     * @return the Title
     */
    public String getTitle() {
        return Title;
    }

    /**
     * @param Title the Title to set
     */
    public void setTitle(String Title) {
        this.Title = Title;
    }


}

The form

<form:form method="post" action="showMovies" modelAttribute="Movie" commandName="Movie">

    <table>
        <tr>
            <td>Title</td>
            <td><form:input path="Title" /></td>
        </tr>
        <tr>
            <td>Date</td>
            <!--Notice, this is normal html tag, will not be bound to an object -->
            <td><input name="date" type="text"/></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="send"/>
            </td>
        </tr>
    </table>

</form:form>

The view:

<body>
    <h3>Here are the list</h3>

     <c:choose> 
        <c:when test="${not empty moviedata.Title}">
            <b>${moviedata.Title}</b>
        </c:when>
        <c:otherwise>
            <b>No Movie yet.</b>
        </c:otherwise>
    </c:choose>
<br />
<br />
    <c:choose> 
        <c:when test="${not empty date}">
            <b>${date}</b>
        </c:when>
        <c:otherwise>
            <b>still nothing.</b>
        </c:otherwise>
    </c:choose>
</body>

Upvotes: 0

Views: 1288

Answers (1)

rax313
rax313

Reputation: 88

Have no idea why but removing the capital "T" in Title worked..

<body>
<h3>Here are the list</h3>

 <c:choose> 
    <c:when test="${not empty moviedata.title}">
        <b>${moviedata.title}</b>
    </c:when>
    <c:otherwise>
        <b>No Movie yet.</b>
    </c:otherwise>
</c:choose>

if anyone can explain why this works it would help me understand SPRING 3.0 faster.. but for now I am just glad I can move on..

Upvotes: 1

Related Questions