Can someone show me a code efficient way to have an object property in spring mvc change based on parameters sent to it from a hyperlink?
I am modifying the spring
Since you asked for a non-verbose solution, you could just do this kind of semi-dirty fix.
@Transient
private Set cats = new HashSet();
[...]
// Call this from OwnerController before returning data to page.
public void parsePets() {
for (Pet pet : getPetsInternal()) {
if ("cat".equals(pet.getType().getName())) {
cats.add(pet);
}
}
}
public getCats() {
return cats;
}
[...]
Cats
Name:
All pets
[...]
/**
* Custom handler for displaying an owner.
*
* @param ownerId the ID of the owner to display
* @return a ModelMap with the model attributes for the view
*/
@RequestMapping("/owners/{ownerId}")
public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
ModelAndView mav = new ModelAndView("owners/ownerDetails");
Owner owner = this.clinicService.findOwnerById(ownerId);
owner.parsePets();
mav.addObject(owner);
return mav;
}
