Package com.nsharmon.iTranslate.model

Source Code of com.nsharmon.iTranslate.model.ITranslateBean

package com.nsharmon.iTranslate.model;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;

import com.nsharmon.iTranslate.l18n.I18n;

public class ITranslateBean {
    @ManagedProperty("#{i18n}")
    protected I18n i18n;
   
  protected Logger logger = Logger.getAnonymousLogger();
 
  public void setI18n(I18n i18n) {
    this.i18n = i18n;
  }   
 
  public void onFail(String key, Object ... args) {
        String msgString = i18n.get(key, args);
    FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, i18n.get("failure"), msgString)
        FacesContext.getCurrentInstance().addMessage(null, msg);   
        FacesContext.getCurrentInstance().validationFailed()
        logger.log(Level.FINE, msgString);
       
        RequestContext context = RequestContext.getCurrentInstance()
        context.addCallbackParam("validationFailed", true)
  }
 
  public void onSuccess(String key, Object ... args) {
        String msgString = i18n.get(key, args);
    FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, i18n.get("success"), msgString)
        FacesContext.getCurrentInstance().addMessage(null, msg);   
        logger.log(Level.FINER, msgString);
       
        RequestContext context = RequestContext.getCurrentInstance()
        context.addCallbackParam("validationFailed", false);         
  }
}
TOP

Related Classes of com.nsharmon.iTranslate.model.ITranslateBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.