Can not access HashMap in the form input tag

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

Can not access HashMap in the form input tag

<input type="text" th:name="${param2.key}" th:value="${param2.value}" />
                               
I had did refer to http://forum.thymeleaf.org/How-to-iterate-HashMap-td3621264.html and used it to reach above code.
The output that i get is:
                <input type="text" name="key1" value="[Ljava.lang.String;@28e2b4c2"/>
                <input type="text" name="key2" value="[Ljava.lang.String;@3bc94186"/>
Not sure how am I getting these strings in the value above.
I printed param in Java code and got this:
param: {key1=value1, key2=value2}
However when i printed param on thml file: {key1=[Ljava.lang.String;@28e2b4c2, key2=[Ljava.lang.String;@3bc94186}

I wonder what am I doing wrong, can someone help?
Thanks in advance.
Rajnish.
rajnish
I'm a rookie in Thymeleaf I'm trying to convert an JSP file to Thymeleaf.
the final output of the JSP/Thymeleaf HTML file should be:
                <input type="text" name="key1" value="value1"/>
                <input type="text" name="key2" value="value2"/>

Here is my code:
Controller:
                HashMap<String, String> param = new HashMap<String, String>();
                param.put("key1", value1);
                param.put("key2", value2);
                request.setAttribute("param", param);

On the HTML Page:

Reply | Threaded
Open this post in threaded view
|

Re: Can not access HashMap in the form input tag

Parminder
You have to get the key/value pair like this:

<input type="text"  th:each="par : ${param}" th:value="${par.value}" th:name="${par.key}" />
Reply | Threaded
Open this post in threaded view
|

Re: Can not access HashMap in the form input tag

rajnish
Thanks Parminder.

That fetches me the same value ([Ljava.lang.String;@49ff75f3 kind of string). Seems i have some issue when i'm passing the param to the thymeleaf.... may i should use another map or something.. going to give this a shot...