diff --git a/src/docbkx/repositories.xml b/src/docbkx/repositories.xml
index ca1eb32c6..d20b1ac6f 100644
--- a/src/docbkx/repositories.xml
+++ b/src/docbkx/repositories.xml
@@ -839,7 +839,9 @@ public class UserController {
private final UserRepository userRepository;
+ @Autowired
public UserController(UserRepository userRepository) {
+ Assert.notNull(repository, "Repository must not be null!");
userRepository = userRepository;
}
@@ -849,7 +851,8 @@ public class UserController {
// Do null check for id
User user = userRepository.findOne(id);
// Do null check for user
- // Populate model
+
+ model.addAttribute("user", user);
return "user";
}
}
@@ -894,8 +897,7 @@ public class UserController {
@RequestMapping("/{id}")
public String showUserForm(@PathVariable("id") User user, Model model) {
- // Do null check for user
- // Populate model
+ model.addAttribute("user", user);
return "userForm";
}
}
@@ -911,23 +913,33 @@ public class UserController {
stateless X to Y conversion approach. We now ship with a
DomainClassConverter that pretty much mimics
the behaviour of
- DomainClassPropertyEditorRegistrar. To register
- the converter you have to declare
- ConversionServiceFactoryBean, register the
- converter and tell the Spring MVC namespace to use the configured
- conversion service:
+ DomainClassPropertyEditorRegistrar. To
+ configure, simply declare a bean instance and pipe the
+ ConversionService being used into it's
+ constructor:
<mvc:annotation-driven conversion-service="conversionService" />
-<bean id="conversionService" class="….context.support.ConversionServiceFactoryBean">
- <property name="converters">
- <list>
- <bean class="org.springframework.data.repository.support.DomainClassConverter">
- <constructor-arg ref="conversionService" />
- </bean>
- </list>
- </property>
+<bean class="org.springframework.data.repository.support.DomainClassConverter">
+ <constructor-arg ref="conversionService" />
</bean>
+
+ If you're using JavaConfig you can simply extend
+ WebMvcConfigurationSupport and hand the
+ FormatingConversionService the configuration
+ superclass provides into the
+ DomainClassConverter instance you
+ create.
+
+ class WebConfiguration extends WebMvcConfigurationSupport {
+
+ // Other configuration omitted
+
+ @Bean
+ public DomainClassConverter<?> domainClassConverter() {
+ return new DomainClassConverter<FormattingConversionService>(mvcConversionService());
+ }
+}
@@ -945,6 +957,9 @@ public class UserController {
int page = Integer.parseInt(request.getParameter("page"));
int pageSize = Integer.parseInt(request.getParameter("pageSize"));
+
+ Pageable pageable = new PageRequest(page, pageSize);
+
model.addAttribute("users", userService.getUsers(pageable));
return "users";
}
@@ -977,7 +992,7 @@ public class UserController {
@RequestMapping
public String showUsers(Model model, Pageable pageable) {
- model.addAttribute("users", userDao.readAll(pageable));
+ model.addAttribute("users", userRepository.findAll(pageable));
return "users";
}
}
@@ -1050,12 +1065,14 @@ public class UserController {
bean declaration directly. In case you might need controller method
specific defaults for the Pageable
simply annotate the method parameter with
- @PageableDefaults and specify page and
- page size as annotation attributes:
+ @PageableDefaults and specify page
+ (through pageNumber), page size (through
+ value) as well as sort (the list of
+ properties to sort by) as wel as sortDir (the direction
+ to sort by) as annotation attributes:
public String showUsers(Model model,
- @PageableDefaults(pageNumber = 0, value = 30) Pageable pageable) { … }
-
+ @PageableDefaults(pageNumber = 0, value = 30) Pageable pageable) { … }