简体   繁体   中英

How to render data from multiple objects to one view

I am having another issue understanding how to render data within a single view.

To begin with I have one controller that returns me a list of cars that I searched. This renders to right side of the screen. Now I need a form on the left side of the screen that will allow me to populate some combo boxes with data to filter on, so for instance:

select state to search for cars in: |--| <--- this is a combo box populated with all states.

select city to search in: |--| <-- a list of us cities to search from

each of the combo boxes listed above are from separate entities.

So how do I populate the car search list ( which comes from the carSearchListController) and the City's and State's

I heard that it's bad practice to call multiple controllers for one view.

what I am getting at is what is the best practice for doing this? I have not found any good information on how to do this the best way.

Thanks

Anything you add to the Model or Session will be available to your view. If its something that needs to live for the life of the session, add it to session. If its something that needs to live only for the life of the request, add it to the model. There are lots of ways to do either, either using annotations or the Model object or a ModelAndView...it all depends on how you have things coded in your controller and what you like using. Spring MVC is quite flexible in that way.

Another approach to your problem, if you want the page to be more "dynamic", would be to load the static bits of data in your controller, then use AJAX requests for the more dynamic pieces. For instance, when most sites do a Search auto-complete, they are usually using AJAX calls to the backend to load the list of auto-completed texts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM