[ 
https://issues.apache.org/jira/browse/OFBIZ-12274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17374320#comment-17374320
 ] 

Daniel Watford commented on OFBIZ-12274:
----------------------------------------

I do like the idea of using FreeMarker's own object wrapper rather than handing 
the escaping of FTL strings in ofbiz. 

MacroFormRenderer was/is full of long lists of string concatenation, requiring 
correct application of escaping at lots of locations. The idea behind 
RenderableFtl and RenderableFtlMacroCall was to encapsulate the awkwardness of 
string escaping in one place - or at least behind the MacroCallParameterValue 
interface.

So I support use of FTL's with_args function.

What I'm not so keen on is having the logic responsible for constructing all 
the parameters of macro calls, such as makeHyperlinkByType, also responsible 
for writing the output of the FTL-to-HTML process to the given Appendable. This 
was one of the reasons that the RenderableFtl interface was created and the 
construction logic pushed out to RenderableFtlFormElementsBuilder.

Incidently, makeHyperlinkByType has already been moved to 
RenderableFtlFormElementsBuilder. The copy that remains in MacroFormRenderer is 
there to support other code in that class that hasn't yet been refactored to 
RenderableFtlFormElementsBuilder. MacroFormRenderer was/is a huge class that 
was difficult to test.

If we continue to use RenderableFtl objects, I think there is an opportunity to 
rework FtlWriter's processFtl(final Appendable writer, final RenderableFtl 
renderableFtl). That method could detect renderableFtl's type and if it was a 
RenderableFtlMacroCall could then retrieve the macro name and parameter map, 
and process the FTL in the same way that you implemented in your PR. This would 
also allow simplification of RenderableFtlMacroCall and probably the complete 
removal of MacroCallParameterValue type hierarchy.




> Add FtlWriter.processWithArgs
> -----------------------------
>
>                 Key: OFBIZ-12274
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-12274
>             Project: OFBiz
>          Issue Type: Improvement
>    Affects Versions: Trunk
>            Reporter: Xin Wang
>            Priority: Major
>
> When calling FTL macro from Java side is needed, instead of crafting a 
> template string with carefully escaping. with newly added 
> FtlWriter.processWithArgs,  we can pass parameters using an environment 
> variable, and then invoke macro with "with_args" builtin. With this approach, 
> it both makes cleaner code and free of fragile escaping.
> As an example, I also changes MacroFormRenderer.makeHyperlinkString to make 
> use of this new facility.
> I have created a GitHub PR for this: 
> https://github.com/apache/ofbiz-framework/pull/307



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to