Last active
January 9, 2018 13:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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