Put dynamic theme Primefaces

Asked

Viewed 435 times

1

I have two templates in my web project. I want to use a different Primefaces theme for each template.

How do I do that?

In the web.xml, when I put the Primefaces theme changes to all templates, but I want each template to have a theme.

  • See if it helps: Link

  • @Douglas He says I need a bean that will return the theme name as a string, but I don’t know how doing this could help me ?

1 answer

0


You can do all this paperwork on ManagedBean. For example:


Usuariomb:

@ManagedBean
@SessionScoped
public class UsuarioMB {

    private String templateSelecionado = "templateDefault.css";
    private String temaSelecionado = "temaDoTemplateDefault";
    private List<String> temasDisponiveis = new ArrayList<String>();

    @PostConstruct
    public void init() {
        if(condicao) { //condição para trocar de tema/template
            templateSelecionado = "templateDiferente.css";
            temaSelecionado = "temaDoTemplateDiferente";
        }
        //Populando os temas
        temasDisponiveis.add("casablanca");
        temasDisponiveis.add("cupertino");
        temasDisponiveis.add("bluesky");
    }

    //getters & setters
}

xhtml template.

<h:outputStylesheet library="css" name="#{usuarioMB.templateSelecionado}" />

paginaParaEscolherTema.xhtml

<p:themeSwitcher value="#{usuarioMB.temaSelecionado}">
    <f:selectItems value="#{usuarioMB.temasDisponiveis}" />
</p:themeSwitcher>

web xml.

<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>#{usuarioMB.temaSelecionado}</param-value>
</context-param>

Explanation:

Through the attributes templateSelecionado and temaSelecionado, both of the type String, it is possible to modify both the css and the Primefaces theme dynamically.

Just make the tag <h:outputStylesheet> use the attribute templateSelecionado and make the page that changes the theme (containing the component <p:themeSwitcher>) and the web.xml use the attribute temaSelecionado.

  • 1

    Igor, excellent explanation and domain in the subject, is a project for college I’m studying to try to develop by the q I saw in your post, it seems q will be the user who will change the theme right ? I would like for example q on the Tutor screen if the theme is South street and in the clinic if the Cupertino thanks for the help from already friend

  • Cool that liked! Thanks :-) It worked?

  • Got it. You can use a ManagedBean ApplicationScoped only to define the theme and template and when loading the Tutor and Clinica pages, make them change the attributes in that ManagedBean.

  • Fine, I’ll try to follow your hint ! Thanks for the help !

  • Cool! I’m going to college now. If you can’t, comment here that at night I make a code and put on github, blz?

  • 1

    Poxa Igor was worth very expensive for the help !!! I’m prototyping the screens first I’ll still try this week anyway, I’ll test when using a BD to do this control at login if tutor opens a menu ( template) with the theme South street if clinical opens with Cupertino ! is a pretty cool animal clinic system the idea I did a project in netbeans I did the tbm theme thing but it was much easier because it was desktop system neah kkk WEB to catch up but still want to learn q possible :-) was worth and good class !

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.