Reputation: 537
I am building a system using spring MVC and now I am doing the *.jsp
page and
I get the following error message :
Invalid property 'flrequest' of bean class [se.lowdin.jetbroker.agent.mvc.FlightRequestBean]: Bean property 'flrequest' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
I have put this code in my flightRequest.jsp:
<tr>
<th>Departure Airport</th>
<td><form:select path="flrequest" items="${airport}"/></td>
</tr>
<tr>
<th>Arrival Airport</th>
<td><form:select path="flrequest" items="${airport}"/></td>
</tr>
And my bean looks like this:
public class FlightRequestBean {
private Customer customer;
private long id;
private FlightStatus flightStatus;
private long numberOfPassengers;
private DateTime datetime;
public void copyValuesToBean(FlightRequest request){
setCustomer(request.getCustomer());
setId(request.getId());
setFlightStatus(request.getFlightStatus());
setNumberOfPassengers(request.getNumberOfPassengers());
setDatetime(request.getDatetime());
}
public void copyBeanToFlightRequest(FlightRequest request){
request.setCustomer(getCustomer());
request.setId(getId());
request.setFlightStatus(getFlightStatus());
request.setNumberOfPassengers(getNumberOfPassengers());
request.setDatetime(getDatetime());
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getNumberOfPassengers() {
return numberOfPassengers;
}
public void setNumberOfPassengers(long numberOfPassengers) {
this.numberOfPassengers = numberOfPassengers;
}
public DateTime getDatetime() {
return datetime;
}
public void setDatetime(DateTime datetime) {
this.datetime = datetime;
}
public FlightStatus getFlightStatus() {
return flightStatus;
}
public void setFlightStatus(FlightStatus flightStatus) {
this.flightStatus = flightStatus;
}
}
I also have a hashmap that contains mocked airports I am trying to display it in my form:select. When I et the error. The indexcontroller holding are having other list that disply well but the hashmap aint displyaing.
@Controller
public class IndexController {
@Inject
CustomerService customerService;
@Inject
FlightRequestService flightService;
@Inject
AirportService airportService;
@RequestMapping("/index.html")
public ModelAndView index() {
List<FlightRequest> requests = flightService.getAllFlightRequest();
List<Customer> customers = customerService.getAllCustomers();
HashMap<Long, Airport>airport = airportService.getAllAirportCodes();
ModelAndView mav = new ModelAndView("index");
mav.addObject("flightRequests", requests);
mav.addObject("customers", customers);
mav.addObject("airportCodes", airport);
return mav;
}
}
Then finally I have my flightRequest controller :
@Controller
@RequestMapping("/flightRequest/{id}.html")
public class FlightRequestController {
@Inject
FlightRequestService service;
@RequestMapping(method = RequestMethod.GET)
public ModelAndView index(@PathVariable long id) {
FlightRequestBean bean = new FlightRequestBean();
if (id > 0) {
FlightRequest flrequest = service.getFlightRequest(id);
bean.copyValuesToBean(flrequest);
}
ModelAndView mav = new ModelAndView("flightRequest");
mav.addObject("flightRequestBean", bean);
return mav;
}
@RequestMapping(method = RequestMethod.POST)
public ModelAndView handleSubmit(FlightRequestBean bean) {
if (bean.getId() > 0) {
FlightRequest flrequest = service.getFlightRequest(bean.getId());
bean.copyBeanToFlightRequest(flrequest);
service.updateFlightRequest(flrequest);
} else {
FlightRequest flrequest = new FlightRequest();
bean.copyValuesToBean(flrequest);
service.createFlightRequest(flrequest);
}
return new ModelAndView("redirect:/index.html");
}
}
So somewhere there is a problem causing that error message. Does anyone have a clue what is the cause of that problem? The error message say something about invalid getters and setters? But how can it be since I am using a hashmap and not
Upvotes: 0
Views: 1187
Reputation: 125272
Your FlightRequestBean
should have an attribute flrequest
with the appropriate getter and setter. The value you select needs to be stored somewhere.
Upvotes: 1