coder
coder

Reputation: 6233

How do I use a variable as the value for the div title attribute

This spring message tag will display the property value of the samples.title.dialog variable on the page:

<spring:message code="samples.title.dialog" text="samples.title.dialog"/>

This div tag only shows the literal string "samples.title.dialog" on the page.

<div id="dialog" title="samples.title.dialog">

How do I use the value of the variable samples.title.dialog as the title of my div tag? When I use the EL expression ${samples.title.dialog} as the title attribute it shows blank on the page.

I'm trying to use a div tag like this:

<div id="dialog" title="${samples.title.dialog}">

Upvotes: 1

Views: 3371

Answers (2)

Brian Kueck
Brian Kueck

Reputation: 11

<spring:message code="samples.title.dialog" var="i18n_dialog" />
${i18n_dialog}

Note: You can't do this, because samples.title.dialog is a read-only property:

<spring:message code="samples.title.dialog" var="samples.title.dialog" />

Upvotes: 1

Asaph
Asaph

Reputation: 162801

Use an EL expression:

<spring:message code="samples.title.dialog" text="${samples.title.dialog}"/>

UPDATE #1:

I think you might be referring to an attribute named samples.title.dialog associated with one of the four scopes: application, request, session or page. Try one of these:

<spring:message code="samples.title.dialog" text="${applicationScope['samples.title.dialog']}"/>
<spring:message code="samples.title.dialog" text="${requestScope['samples.title.dialog']}"/>
<spring:message code="samples.title.dialog" text="${sessionScope['samples.title.dialog']}"/>
<spring:message code="samples.title.dialog" text="${pageScope['samples.title.dialog']}"/>

UPDATE #2:

It looks like you're actually trying to use a value defined in a Spring Internationalization properties file. Check out this Spring Internationalization example and verify that you've done all the steps correctly to wire things up.

Upvotes: 2

Related Questions