Skip to content

Instantly share code, notes, and snippets.

@jhorsman
Last active January 9, 2018 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhorsman/c14c076fd2a5bb27ba73be78c77ad2eb to your computer and use it in GitHub Desktop.
Save jhorsman/c14c076fd2a5bb27ba73be78c77ad2eb to your computer and use it in GitHub Desktop.
Custom page controller for DXA JAVA. Also see https://tridion.stackexchange.com/a/18256/88
@Controller
public class MyPageController {
// Inject the PageController, because we cannot override and change the RequestMapping
@Autowired
private PageController pageController;
// This mapping is more specific than the DXA PageController mapping
@RequestMapping(
value = {"/**"},
produces = {"text/html", "*/*"},
method = {RequestMethod.GET, RequestMethod.POST}
)
public String handleGetPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
String view = pageController.handleGetPage(request, response);
PageModel pageModel = (PageModel) request.getAttribute("pageModel");
pageModel = this.enrichModel(pageModel, request);
request.setAttribute("pageModel", pageModel);
return view;
}
// enrich the page model, with the DXA enrichModel() pattern
protected PageModel enrichModel(PageModel pageModel, HttpServletRequest httpServletRequest) throws Exception {
//do your thing here
pageModel.setTitle("Hello, World!");
return pageModel;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment