[MAGNOLIA-7864] ctx.getParameters()/ctx.getParameter('Param') returns only first occurance of paramater Created: 17/Aug/20  Updated: 19/Aug/20  Resolved: 19/Aug/20

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Bartosz Staryga Assignee: Unassigned
Resolution: Not an issue Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

Having:
?Topic=typhoon&Topic=hurricane&foo=bar

ctx.getParameters() would return:

*Hash (2)
  foo = "bar" (String)
  Topic =* "typhoon" (String)

ctx.getParameter('Topic') would return:

"typhoon" (String)

We would expect to get all values.
Either to have multi values or array of all params.

 



 Comments   
Comment by Roman Kovařík [ 17/Aug/20 ]

Hi bstaryga

you can use ctx.getParameterValues

Hope that helps
Roman

Comment by Richard Gange [ 17/Aug/20 ]

I think you could workaround that by using a comma.

?Topic=typhoon,hurricane&foo=bar
Comment by Roman Kovařík [ 19/Aug/20 ]
<#list ctx.getParameterValues("test") as i>
- ${i}
</#list>

http://localhost:8080/magnoliaAuthor/travel.html?test=1&test=2

Output:

- 1 - 2
Comment by Bartosz Staryga [ 19/Aug/20 ]

rkovarik  Aaaa there you go i did not pass the param, but then if param is needed then it's not of use to me.
Frankly I need what `getParameters()` does, so all key, value pairs. As we do diffrent things based on keys, and we do not know which keys are used, so always getting all values for all possible keys is bit cumbersome.

Anyway, I already implemented a small freemarker function that returns for me array of all key value pairs.

Also since no html nor url specs says that keys needs to be unique (actullay html5 mentiones they do not have to) ctx.getParameters()/ctx.getParameter('Param') should return all

Comment by Richard Gange [ 19/Aug/20 ]

Anyway, I already implemented a small freemarker function that returns for me array of all key value pairs.

Paste it here for the community...

Comment by Bartosz Staryga [ 19/Aug/20 ]
[#function function__getParameters]
  [#assign getParameters__parameters = []]
  [#assign getParameters__queryString = ctx.getRequest().getQueryString()!]

  [#if getParameters__queryString?has_content]
    [#assign getParameters__queryString = getParameters__queryString?split('&')]

    [#list getParameters__queryString]
      [#items as getParameters__queryString__item]
        [#assign getParameters__pair = getParameters__queryString__item?split('=')]
        [#assign getParameters__parameters += [\{'key': getParameters__pair[0]!, 'value': getParameters__pair[1]!}]]
      [/#items]
    [/#list]
  [/#if]

  [#return getParameters__parameters]
[/#function]
Generated at Mon Feb 12 04:27:31 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.