How are request parameters mapped into RenderingModel of magnolia?

908 views Asked by At

Im using Magnolia RenderingModel in combination with Freemarker. I have URLs like the following:

http://anyPath/context?productTypes=XXXXX&productTypes=YYYYY

my rendering model class looks like:

 class MyModel extends RenderingModelImpl {
   ...
   private String[] productTypes;
   ...
 }

However the mentioned array contains only the first value, but not the second. I checked the behaviour of template directives like ctx.getParameters(). This shows the same behaviour, I get only the first value returned. But if im using ctx.getParameterValues(paramName), it returns both values.

This leads me to following questions:

  • How would I go, if I want to lookup how the request parameters are mapped into the rendering model, or better:
  • How can i change the behaviour of that ?
  • Can anyone acknowledge, that this behaviour is wrong ?
1

There are 1 answers

0
Jan On BEST ANSWER

It used to be mentioned in documentation and I believe it still is - if you use .getParameters() you get only first value for multivalue parameter. If you want to get all the values, you need to use .getParameterValues(String param).

From what I understand reasons for that were backward compatibility.

As for changing the behavior, you would need to write your own renderer (e.g. by extending default FreemarkerRenderer and override info.magnolia.rendering.renderer.AbstractRenderer.newModel(Class<T>, Node, RenderableDefinition, RenderingModel<?>) method which instantiates and populates the model class.

Alternatively you can provide fix for above set population method and submit it to Magnolia as a patch. While the .getParameters() behavior is iirc on purpose, the model param population might not be, so you have high chance of getting that changed.