Search code examples
javajspsessionstruts2ognl

Passing a value coming from a session to font-size attribute


I need your help in order to solve a question. I need to set the font size according to a value I stored into a session. I need to write something similar to

<a href="/chips" style="font-size: (#session.soglia)pt"><s:property value="nome"/></a>

but this does not work! How can I do? The font size is stored into a session because it can dinamically change (an action class calculates it before calling the jsp page). Thank you!!!


Solution

  • The font size is stored into a session because it can dinamically change (an action class calculates it before calling the jsp page).

    This does not explain why the session is needed here, but however...

    to access a Session attribute, an Action attribute or whatever with OGNL, you need to use Struts Tags.

    <a href="/chips" style="font-size: <s:property value='#session.soglia'/>pt">
        <s:property value="nome"/>
    </a>
    

    Otherwise you'd need to use JSP EL. But don't.

    Off-topic: it's worth noting that today we have more proficient ways to handle font sizes than points, eg. with Viewport Sized typography.