How to use Parameterized MessageFormat with non-Value attributes of JSF components

Viewed 4126

I have use case in which I have to use resource bundle to display various texts on UI. Some of these resource bundle entries take paramets (e.g. {0}), for these I use h:outputFormat but sometimes that isn't enough.

e.g.

someMessage=Display this message with param {0}

in a resource bundle.

To display it on xhtml I normally do:

<h:outputFormat value="#{msg['someMessage']}"><f:param value="#{someBean.value}"/></h:outputFormat>

That works well when it's a simple case, but for more complex use cases it isn't enough. For example if I want the 'title' attribute of a commandLink to use the above resource bundle entry:

    <h:commandLink action="logout" title="#{msg['someMessage']}">
        <f:param value="#{someBean.value}" />
        <h:graphicImage library="images" name="image.png" />
    </h:commandLink>

which doesn't work. I also tried:

    <h:commandLink action="logout">
        <f:attribute name="title">
            <h:outputFormat value="#{msg['someMessage']}"><f:param value="#{someBean.value}"/></h:outputFormat>
        </f:attribute>
        <h:graphicImage library="images" name="image.png" />
    </h:commandLink>

which also doesn't work since f:attibute doesn't allow children.

Even if there is a hack to bypass this (e.g. using hover component from primefaces) there are other fields that might require a parameterized message.

Does anyone know of a way to use MessageFormat that takes an argument in a non-value field of a JSF component?

1 Answers
Related