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