2
I’m using Struts2
to build a web application. I have a method in a class called BaseAction
, where all other actions extend it, as written below:
public boolean isUserFullyLogged() {
final Boolean isLogado = (Boolean) this.retrieveSessionAttribute(Constantes.LOGADO);
return (isLogado != null) && isLogado.booleanValue();
}
I want to access this method in my JSP to show or not certain content and tried the syntax below for this:
<s:if test="#userFullyLogged">Conteúdo</s:if>
<s:if test="%{#userFullyLogged}">Conteúdo</s:if>
<s:if test="userFullyLogged">Conteúdo</s:if>
<s:if test="%{userFullyLogged}">Conteúdo</s:if>
But none of them worked and the method just isn’t called. Does anyone know where I’m wrong and what the correct syntax to call a method in the back-end?
Why not just check the attribute in the session directly? To avoid repeating the test on all pages (improving maintenance), you could create a custom tag whose content is only rendered when the user is logged in and another for when not logged in. A tag file would be very practical.
– utluiz