|
|
|
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.samples.petclinic.web; |
|
|
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
@ -8,15 +9,15 @@ import org.springframework.samples.petclinic.Owner;
@@ -8,15 +9,15 @@ import org.springframework.samples.petclinic.Owner;
|
|
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
|
import org.springframework.ui.Model; |
|
|
|
|
import org.springframework.validation.BindingResult; |
|
|
|
|
import org.springframework.web.bind.WebDataBinder; |
|
|
|
|
import org.springframework.web.bind.annotation.InitBinder; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
|
import org.springframework.web.bind.annotation.InitBinder; |
|
|
|
|
import org.springframework.web.bind.WebDataBinder; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* JavaBean Form controller that is used to search for <code>Owner</code>s by |
|
|
|
|
* last name. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
* @author Ken Krebs |
|
|
|
|
* @author Arjen Poutsma |
|
|
|
@ -26,6 +27,7 @@ public class FindOwnersForm {
@@ -26,6 +27,7 @@ public class FindOwnersForm {
|
|
|
|
|
|
|
|
|
|
private final Clinic clinic; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
public FindOwnersForm(Clinic clinic) { |
|
|
|
|
this.clinic = clinic; |
|
|
|
@ -33,23 +35,23 @@ public class FindOwnersForm {
@@ -33,23 +35,23 @@ public class FindOwnersForm {
|
|
|
|
|
|
|
|
|
|
@InitBinder |
|
|
|
|
public void setAllowedFields(WebDataBinder dataBinder) { |
|
|
|
|
dataBinder.setDisallowedFields(new String[] {"id"}); |
|
|
|
|
dataBinder.setDisallowedFields("id"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/owners/search", method = RequestMethod.GET) |
|
|
|
|
public String setupForm(Model model) { |
|
|
|
|
public String setupForm(Model model) { |
|
|
|
|
model.addAttribute("owner", new Owner()); |
|
|
|
|
return "owners/search"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/owners", method = RequestMethod.GET) |
|
|
|
|
public String processSubmit(Owner owner, BindingResult result, Model model) { |
|
|
|
|
|
|
|
|
|
public String processSubmit(Owner owner, BindingResult result, Model model) { |
|
|
|
|
|
|
|
|
|
// allow parameterless GET request for /owners to return all records
|
|
|
|
|
if(owner.getLastName() == null) { |
|
|
|
|
if (owner.getLastName() == null) { |
|
|
|
|
owner.setLastName(""); // empty string signifies broadest possible search
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// find owners by last name
|
|
|
|
|
Collection<Owner> results = this.clinic.findOwners(owner.getLastName()); |
|
|
|
|
if (results.size() < 1) { |
|
|
|
|