Hello,

OFBIZ-11900 covers the work-in-progress effort to refactor
MacroFormRenderer by extracting code which builds strings to be executed as
FTL macros into a separate builder class.

This github branch [1] contains the work-in-progress changes for this
issue. Please take a look at this branch and highlight any concerns with
the approach. This will give me a chance to address concerns or change
approach before too much further work is done.

Further to simply extracting code from MacroFormRenderer to a separate
builder I wanted to avoid the use of strings to represent FTL macro calls.
Instead I added an interface called RenderableFtl to represent an element
that can be rendered as part of a FreeMarker template.

So far the main RenderableFtls in use are RenderableFtlMacroCall and
RenderableFtlString.

RenderableFtlString can be used to represent a pre-rendered HTML string as
used to construct hidden forms by WidgetWorker.

RenderableFtlMacroCall is probably the most important of the RenderableFtl
classes as it can be used in place of the strings previously built in
MacroFormRenderer to capture an FTL macro call, but without the need for
the caller to append quoting and whitespace delimiters for each additional
macro call parameter.

All the RenderableFtl classes know how to render themselves to a String
which will be used by FtlWriter to process the string as an FTL element and
then write the result to an Appendable.

The reason for these changes are to separate the various concerns involved
in rendering a form:
- RenderableFtl objects are responsible for rendering their data to an FTL
compliant string.
- FtlWriter is responsible for processing FTL compliant strings as part of
an FTL template and writing the results to an Appendable.
- RenderableFtlFormElementsBuilder is responsible for creating
RenderableFtl objects for various FieldInfo objects, replacing the FTL
macro call strings which were previously built in MacroFormRenderer.
- MacroFormRenderer is responsible for orchestrating calls to
RenderableFtlFormElementsBuilder to create multiple RenderableFtl objects
as needed for rendering a field and passing them to FtlWriter. For example,
rendering a DisplayEntityField produces RenderableFtl objects representing
the displayed field, an associated hyperlink and a tooltip.

Separating these concerns makes testing easier:
- MacroFormRendererTest can test orchestration of MacroFormRender's calls
to RenderableFtlFormElementsBuilder, rather than having to analyse the
strings previously written.
- Testing of RenderableFtlFormElementsBuilder focuses on the production of
correctly configured RenderableFtl elements based on the given FieldInfo
objects, rather than testing the eventual string rendered.
- The RenderableFtl objects can be tested by examining the FTL strings
produced.

To support testing of RenderableFtlFormElementsBuilder a number of Hamcrest
Matchers have been created to check that RenderableFtlMacroCall objects
have expected name and parameter values.

Please excuse the long message :) and please let me know if you have any
comments or concerns about the approach I have taken.

Thanks,

Dan.

[1] - https://github.com/danwatford/ofbiz-framework/tree/OFBIZ-11900-WIP

-- 
Daniel Watford

Reply via email to