Renderer doesnt restore the model attribute after rendering is done
-------------------------------------------------------------------

                 Key: MAGNOLIA-3304
                 URL: http://jira.magnolia-cms.com/browse/MAGNOLIA-3304
             Project: Magnolia
          Issue Type: Bug
          Components: templating
    Affects Versions: 4.3.6
            Reporter: Tobias Mattsson
            Assignee: Ondřej Chytil


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 <[email protected]>

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


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.magnolia-cms.com/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira




----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to