Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Custom page controller for DXA JAVA. Also see
public class MyPageController {
// Inject the PageController, because we cannot override and change the RequestMapping
private PageController pageController;
// This mapping is more specific than the DXA PageController mapping
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