Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert integer value to string using JSTL/EL

Tags:

java

jsp

jstl

el

How do I correct this statement:

${model.myHashtable[model.data.id]}.

myHashtable is defined as

Hashtable<String, String>

But, ${model.data.id} returns an int.

I tried to do something like

${model.myHashtable['model.data.id']}

But it does not work. Any other ideas, aside from changing the type of id to String?

like image 790
geffchang Avatar asked Aug 26 '10 14:08

geffchang


2 Answers

Set it as body of <c:set>. It will implicitly be converted to String.

<c:set var="idAsString">${model.data.id}</c:set>
<c:out value="${model.myHashtable[idAsString]}" />
like image 50
BalusC Avatar answered Oct 14 '22 22:10

BalusC


${''.concat(model.data.id)} works for me,you may try it.

like image 27
Chaojun Zhong Avatar answered Oct 14 '22 23:10

Chaojun Zhong