Class DynamicViewSourceGenerator

java.lang.Object
io.jmix.dynmodelflowui.impl.DynamicViewSourceGenerator

@Component("dynmod_DynamicViewSourceGenerator") public class DynamicViewSourceGenerator extends Object
Generates the literal XML source of a template-based dynamic entity view, so the Admin UI can offer "render the template, then edit the XML by hand" instead of writing a descriptor from scratch.

The edited model does not have to be applied: the template is rendered against a preview metadata session built from the whole edited model (DynamicModelManager.buildPreviewSession(io.jmix.dynmodel.meta.DynamicModelDefinition)), so a never-applied entity and attributes added in the current editing session are reflected. The result is what an apply of the same declaration would render, including the title resolution of DynamicViewDeployer.resolveTitle(java.lang.String, io.jmix.dynmodel.meta.DynamicViewDefinition, io.jmix.dynmodel.meta.DynamicViewType).

The rendered XML is re-indented before it is returned, because a template renders component fragments and macro bodies at their own indentation and leaves blank lines where a directive produced nothing.

  • Field Details

  • Constructor Details

    • DynamicViewSourceGenerator

      public DynamicViewSourceGenerator()
  • Method Details

    • generateSource

      public String generateSource(DynamicModelDefinitionModel model, DynamicEntityModel entity, DynamicViewModel view)
      Renders the template of the given view declaration into XML source.
      Parameters:
      model - the whole edited model, used to build the preview metadata session
      entity - the entity owning the view
      view - the view declaration being edited; its template, parameters, id, and title are taken from this object, not from model, because the editor may hold changes not yet merged into the model graph
      Returns:
      the rendered view XML, pretty-printed
      Throws:
      IllegalArgumentException - when the declaration or the model is invalid
    • prettyPrint

      protected String prettyPrint(String xml)
      Re-indents the given XML with one element per line. Source that cannot be parsed is returned unchanged, so that a template producing invalid XML still ends up in the editor where the user can fix it.