UI: Refactor duplicate template rendering code #424
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While trying to add a new feature to the user interface I discovered that each of the Resource classes duplicates the same code for rendering Freemarker templates. Rather than creating yet another copy of it I'd prefer to first refactor and eliminate the duplication.
This replaces the various copies of the Freemarker configuration with one shared instance attached to the application object. It also introduces a render() helper in BaseResource that sets up the common view parameters and returns a HTML Representation.
I've removed the calls to representation.setCharacterSet(UTF_8) as WriterRepresentation's parent's constructor ends up calling that anyway.
Note that EngineResource uses DefaultObjectWrapper while the other pages use BeansWrapper, so I added an overload to render() to preserve that difference. It'd be nice if they used the same configuration but I'll leave tackling that for future.