Plantillas Primefaces JSF
  • Introduction
  • Proyecto JEE
    • Introduccion
    • POSEIDON
    • Descomprimir template
    • Proyecto JEE
    • Dependencias
    • Sources
    • Ejecutar proyecto
    • TEMPLATE RESPONSIVE
    • Plantilla Bootfaces
      • Introduction
      • Plantilla
        • Clonar Template
        • Proyecto EJB
        • Proyecto Web
        • template base
        • top
        • footer.xhtml
        • Properties
        • Roles
        • Util
        • template base
        • page
  • Capitulo II. Crear EJB
    • MongoDB
    • Proyecto EJB
    • Dependencias
    • Paquetes
    • Provider
    • Entity
    • Repository
    • Converter
    • Services
    • Datamodel
  • Capitulo III. Configuracion
    • Paquetes
    • Util
    • Properties
    • Template
    • Footer
    • Logo
    • Componentes
  • Capitulo IV. Login
    • Dependencias ejb
    • Roles
    • ApplicationMenu
    • RolAdministrador
    • ValidadorRoles
    • LoginController
    • Login.xhtml
  • Capitulo V. Menu
    • Menu
  • Capitulo VI Controller
    • Controller Simple
    • Implementar IController
    • Colapsar Codigo
    • Atributos
    • GetPages
    • Init
    • Reset
    • Prepare
    • ShowAll
    • IsNew
    • Save
    • Edit
    • Delete
    • Print
    • handleSelected
    • Paginacion
    • Codigo Completo
  • Capitulo VII Formularios
    • Carpetas
    • list.xhtml
    • new
    • view
  • Capitulo X Referenciados y Embebidos
    • Referenciados
  • Plantilla Bootfaces
    • Untitled
Powered by GitBook
On this page
  • Idiomas.java
  • ResourcesFiles.java
  • Codigo completo

Was this helpful?

  1. Capitulo III. Configuracion

Util

PreviousPaquetesNextProperties

Last updated 6 years ago

Was this helpful?

Dentro del paquete util

Crear las clases Idiomas.java, ResourcesFiles.java

Idiomas.java

Indicamos el soporte para varios lenguajes.

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
 * and open the template in the editor.
*/
package com.avbravo.spard.util;

import java.io.Serializable;
import java.util.Locale;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @authoravbravo
 */
@Named
@SessionScoped
public class Idiomas implements Serializable {

    private static final long serialVersionUID = 1L;
    @Inject
    ResourcesFiles rf;
    private String locale = Locale.getDefault().getDisplayLanguage();

    public void setLocale(String locale) {
        this.locale = locale;
    }

    public synchronized String getLocale() {
        return locale;
    }

    public synchronized String changeLanguage() {
        return "changed";
    }

    public Idiomas() {
    }

    public String englishAction() {
        FacesContext context = FacesContext.getCurrentInstance();
        context.getViewRoot().setLocale(Locale.ENGLISH);
        this.locale = "en";
        rf.saveLocale();
        return null;
    }

    public String spanishAction() {
        FacesContext context = FacesContext.getCurrentInstance();
        context.getViewRoot().setLocale(new Locale("es"));
        this.locale = "es";
        rf.saveLocale();
        return null;
    }




}

ResourcesFiles.java

En el método saveLocale() indicar la ruta del archivo properties.,

  public void saveLocale() {
        currentLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        mrb = ResourceBundle.getBundle("com.avbravo.spard.properties.messages",
                currentLocale);
        arb = ResourceBundle.getBundle("com.avbravoutils.properties.application",
                currentLocale);
    }

Codigo completo

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
 * and open the template in the editor.
*/
package com.avbravo.spard.util;

import java.io.Serializable;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;

/**
 *
 * @authoravbravo
 */
@Named
@SessionScoped
public class ResourcesFiles implements Serializable {

    private static final long serialVersionUID = 1L;
    Locale currentLocale;
    ResourceBundle mrb; //for messages atributos
    ResourceBundle arb; //for application

    public ResourcesFiles() {
    }

    @PostConstruct
    public void init() {
        saveLocale();
    }

    public void saveLocale() {
        currentLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        mrb = ResourceBundle.getBundle("com.avbravo.spard.properties.messages",
                currentLocale);
        arb = ResourceBundle.getBundle("com.avbravoutils.properties.application",
                currentLocale);
    }


    public Locale getCurrentLocale() {
        return currentLocale;
    }

    public void setCurrentLocale(Locale currentLocale) {
        this.currentLocale = currentLocale;
    }

    public ResourceBundle getMrb() {
        return mrb;
    }

    public void setMrb(ResourceBundle mrb) {
        this.mrb = mrb;
    }

    public ResourceBundle getArb() {
        return arb;
    }

    public void setArb(ResourceBundle arb) {
        this.arb = arb;
    }
    /*
     *Devuelve el mensaje Mrb
     */

    public String getMessage(String mensaje) {
        return mrb.getString(mensaje);
    }
    /*
     *Devuelve el mensaje Arb
     */

    public String getAppMessage(String mensaje) {
        return arb.getString(mensaje);
    }


}