Spring Preliminary List of MVC JSTL

I have 2 objects: Car and person

A person has the following attributes: A int id, String name, List<Car> cars car has the following variables:

int id, String make

I am trying to create an update view for a person.

I pass a person object and a model attribute list containing all the cars

person.cars = {"BMW","MERCEDES"}

allCars = {"BMW","TOYOTA","HONDA","MERCEDES","KIA","HYUNDAI"}

When I use <form:select/>with <form:options items=${allCars} .. />, I see all the cars ..

I was wondering if there is a spring way without writing many JSTL loops to pre-select the cars that a person has.

thank

+3
source share
2 answers

In this particular case, the key decision was to override the equals method of the Car class.

, spring , , , ,

+2

, , .

<form:checkboxes 
path="person.cars" 
items="${allcars}" 
itemLabel="make" 
itemValue="id"/>

, .

0

All Articles