Ant Waters
Ant Waters

Reputation: 580

JSF h:commandLink with hml entity characters, superscript etc

What is the best way of using special characters and formatting in a dynamically generated h:commandLink?

I am rendering an equation (e.g. A=π*r2) as a list of h:commandLink items, so that each symbol in the equation can be separately clicked:

JSF:

<ui:repeat value="#{eqBean.eqSymbolDisplays}" var="eqSym">
  <h:commandLink value="#{eqSym.text}" styleClass="#{eqSym.styleClass}" action="#{eqBean.eqSymbolClick(eqSym)}" />
</ui:repeat>                                

Bean:

public String getText(){
    // Return the text for a given symbol
}

The question is what the getText method should do when the symbol needs a special character, special mathematical symbol, and/or needs to be a super-script or sub-script?

Here are some specific problems/questions:

(1) How do I use the greek letter π symbol in a CommandLink? If I return &pi; then that is what gets displayed, not the greek symbol

(2) What is the best way to do a superscript in a CommandLink? I could use a CSS style but some people say that is a bad idea, especially when the superscript implies meaning, rather than just presentation, as it does for a number raised to a power. See :

Beware CSS for Superscript/Subcript

Upvotes: 1

Views: 808

Answers (1)

Ant Waters
Ant Waters

Reputation: 580

The answer was obvious in the end: Just replace the value attribute of the h:commandLink with a child h:outputText element that has escape="false" :

JSF:

<ui:repeat value="#{eqBean.eqSymbolDisplays}" var="eqSym">
  <h:commandLink styleClass="#{eqSym.styleClass}" action="#{eqBean.eqSymbolClick(eqSym)}" >
    <h:outputText value="#{eqSym.htmlText}" escape="false"/>
  </h:commandLink>
</ui:repeat>                                

Upvotes: 2

Related Questions