0

I am using JSF 2.2 and PrimeFaces 5.2.

I have the following inside my body on my view:

<div class="headerDetails">

    <h1> Nombre Empresa: #{loginController.login.empresa} </h1>

    <h1> Bienvenido: #{loginController.login.nombre}</h1>

</div>

I want to dynamically hide and show the first <h1> depending on what user logged in. What is the best way of accomplishing this?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Erick
  • 823
  • 16
  • 37
  • 3
    You could enclose `

    ` (and `

    `, if needed) inside a standard JSF component like `` (or ``) specifying the desired condition in the `rendered` attribute. This will conditionally render an HTML `
    ` element (without `layout="block"`, it will render an HTML `` element, if one of the attributes like `id`, `style`, `styleClass` is specified).

    – Tiny Dec 05 '15 at 19:29
  • Excellent! It worked! I should have known how to do that – Erick Dec 05 '15 at 19:39

1 Answers1

1

This is what I did for those who are interested:

<div class="headerDetails">

    <h:panelGroup layout="block" rendered="#{loginTipoController.isEmpresarial()}">

        <h1> Nombre Empresa: #{loginController.login.empresa} </h1>

    </h:panelGroup>

    <h1> Bienvenido: #{loginController.login.nombre}</h1>

</div>

My controller looks like this:

@ManagedBean
@ApplicationScoped
public class LoginTipoController {

    private LoginTipo tipo;

    public LoginTipo getTipo() {
        return tipo;
    }

    public void setTipo(LoginTipo tipo) {
        this.tipo = tipo;
    }

    @PostConstruct
    public void init()
    {   
        tipo = new LoginTipo();

        //setting the value from get request
        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

        tipo.setTipo(params.get("tipo"));
    }

    public boolean isEmpresarial()
    {
        if(tipo.getTipo().equals("emp")) return true;

        else return false;
    }

}

If the user is "ind", I don't want to show the <h1> tag. If it is "emp", I want to show the tag.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Erick
  • 823
  • 16
  • 37