internationalizationstruts2ognlstruts-tags

Dynamic tooltip in JSP using Struts 2


I'm trying to add a tooltip to a series of buttons. The text is dynamic in that, it needs a parameter (shows a text with a page number), which is stored in global.properties:

page.nr.tooltip=Go to page {0}

I've tried several things, none of them works:

title="<s:text name='page.nr.tooltip'>
        <s:param value='pageNum' />
        </s:text>"

I've also tried setting a variable and using this:

<s:set var="ttStr" value="<s:text name='page.nr.tooltip'>
        <s:param value='pageNum' />
        </s:text>" />

But I can't seem to use it as a tooltip-text either. Tried either of these (and more)

value="ttStr"
value="$ttStr"
value="#attr[#ttStr]"

which won't display the text. Any suggestions? JavaScript is not possible because the application has to run in browsers with JS turned off.

I'm probably missing something really simple...

EDIT:

Guess I need to clarify a bit: pageNum is a variable I set like this:

<s:set var="pageNum" value="..." />

and it is valid, since I can use it, and it has the correct value. I want to add the pageNum as a variable to the tooltip-text, something like this:

<s:submit type="button" class="..."
   title="<s:text name='page.nr.tooltip'>
             <s:param value='pageNum' />
          </s:text>">
...

This will not render the tooltip as "Go to page 4" (or whatever value pageNum has). It renders to "<s:text name='page.nr.tootip' ..." - in other words the exact text in quotes from the example above.

I know how to set and use variables from the action class - that wouldn't help here though.

The title-attribute doesn't render the value "Go to page " at all. Even if I just write

<s:submit type="button" class="..."
       title="<s:text name='page.nr.tooltip'/>"

it displays <s:text name='page.nr.tooltip'/> as the tooltip text. Surprised, this isn't working for me.


Solution

  • You cannot use tag inside another tag attribute. Use var attribute of <s:text> tag to push value to the value stack. And then use OGNL to get this value in the title attribute of the <s:submit>.

    <s:text var="pageTooltip" name="page.nr.tooltip">
        <s:param value="#pageNum"/>
    </s:text>
    
    <s:submit type="button" title="%{#pageTooltip}"/>