Convert integer value to string using JSTL/EL

Viewed 39506

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?

5 Answers

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

In JSP file:

<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>

<!-- lines of code... -->

<fmt:parseNumber var = "id_value" type = "number" value = "${model.data.id}" />
<c:out value = "${id_value}" />

The $ {model.data.id} returns an integer, use Hashtable <Integer, String>, which solves my problem. If the id is a number, then <c:set> is useless.

Related