Request parameter

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Request parameter

Zemi
Administrator
Hello,

this is a very basic question but I cannot find any example in the documentation and examples.

Given the URL http://www.example.com/mypage.html?foo=bar I can print the request parameter value "bar" doing:

   < span th:text="${param.foo[0]}" > ... < /span >

Is there any way to avoid typing the array index [0]?

Reply | Threaded
Open this post in threaded view
|

Re: Request parameter

danielfernandez
Administrator
Hi,

Technically, request parameters are always arrays, as they can be multi-valued. That's in fact what the HttpServletRequest "getParameterValues()" returns (a String[]).

Although it could be possible to add to Thymeleaf's WebContexts a way to access single-valued parameters without the array notation, this would mean storing single-valued parameters as String, and multi-valued parameters as String[]. But this would lead to inconsistencies when a multi-valued parameter comes with only one value --for example, because a user only selected one value from a set of checkboxes in a form--, because in that case this parameter would have to be accessed in one way when the user selected only one check, and in a different way when the user selected more than one.

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: Request parameter

Zemi
Administrator
In reply to this post by Zemi
Hi,

thank you very much for your response.

I understand your design decission, I only wanted to be sure that I was using the right syntax.

Regards,
   Zemi