Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-3304

Renderer doesnt restore the model attribute after rendering is done

    XMLWordPrintable

Details

    Description

      Before rendering AbstractRenderer.saveContextState() takes a snapshot of the values it will change, but this doesnt include "model". Then AbstractRenderer.setupContext() sets "model", afterwards the snapshot is used to restore the attributes but this doesnt include "model".

      Reported on the user list by Stein Kvarud <stein.kvarud@iterate.no>

      Original description:

      Hi.

      I discovered some sideeffects with the way magnolia does paragraph
      loading that to me seems like a bug.
      When including a paragraph the model reference are set to the model of
      the paragraph. Next when the rendering of the paragraph is done I
      expected the model reference to be set back to the template rendering
      model, but the reference stays at the model class of the final
      paragraph.
      This can cause some strange sideeffects because the reference to the
      model in the template are influenced by the paragraphs added to the
      page.

      I have created a small sample to illustrate the problem.

      Creating two custom RenderingModels for a template and a paragraph

      public class MyTemplateRenderingModel extends
      RenderingModelImpl<RenderableDefinition> {

      public MyTemplateRenderingModel(Content content,
      RenderableDefinition definition, RenderingModel<?> parent)

      { super(content, definition, parent); }

      public String getClassName(){ return this.getClass().getName(); }

      }

      public class MyParagraphRenderingModel extends
      RenderingModelImpl<RenderableDefinition> {

      public MyParagraphRenderingModel(Content content,
      RenderableDefinition definition, RenderingModel<?> parent) { super(content, definition, parent); }

      public String getClassName()

      { return this.getClass().getName(); }

      }

      Then adding two smal jsp files

      The template:

      Model value before loading paragraphs = ${model.className}

      <cms:contentNodeIterator contentNodeCollectionName="testCollection">
      <cms:includeTemplate />
      </cms:contentNodeIterator>
      <cms:newBar contentNodeCollectionName="testCollection"
      paragraph="testParagraph" newLabel="New test paragraph" />

      Model value after loading paragraphs = ${model.className}

      The paragraph:

      <p>
      Model class name inside paragraph = ${model.className}
      </p>

      Then I add a modelClass for the paragraph and the template in the
      magnoli configuration.

      Before adding any paragraphs to the template it displays

      Model value before loading paragraphs = MyTemplateRenderingModel
      Model value after loading paragraphs = MyTemplateRenderingModel

      I then add one (or more) paragraphs
      Model value before loading paragraphs = MyTemplateRenderingModel
      Model class name inside paragraph = MyParagraphRenderingModel
      Model value after loading paragraphs = MyParagraphRenderingModel

      As the example illustrates the final output from model.className
      refers to the paragraph and not the template.

      Do I need to add some tag to the jsp to avoid this sideeffect or is this a bug?

      Regards
      Stein

      Checklists

        Acceptance criteria

        Attachments

          Issue Links

            Activity

              People

                tmattsson Tobias Mattsson
                tmattsson Tobias Mattsson
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  Checklists

                    Bug DoR
                    Task DoD