Package org.boco.seamUtility.converter

Source Code of org.boco.seamUtility.converter.IntegerDummyConverter

/***************************************************************************
* Copyright (c) 2004 - 2008  Fabrizio Boco fabboco@users.sourceforge.net  *
*                                                                         *
*                                                                         *
*   This is free software; you can redistribute it and/or                 *
*   modify it under the terms of the GNU Library General Public           *
*   License (version 2.1) as published by the Free Software Foundation    *
*                                                                         *
*   This library  is distributed in the hope that it will be useful,      *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this library; see the file COPYING.LIB. If not,    *
*   write to the Free Software Foundation, Inc., 59 Temple Place,         *
*   Suite 330, Boston, MA  02111-1307, USA                                *
*                                                                         *
***************************************************************************/
/**
- $Header: /usr/local/cvslocalrepository/SeamUtility/src/org/boco/seamUtility/converter/IntegerDummyConverter.java,v 1.2.4.3 2008/06/07 17:08:11 fab Exp $
- $Author: fab $
- $Revision: 1.2.4.3 $
- $Date: 2008/06/07 17:08:11 $


- $Log: IntegerDummyConverter.java,v $
- Revision 1.2.4.3  2008/06/07 17:08:11  fab
- Correzione di tutti DummyConverter
-
- Revision 1.2.4.2  2008/04/22 06:14:35  fab
- Aggiornamento indirizzo di posta
-
- Revision 1.2.4.1  2008/04/19 11:14:41  fab
- Aggiornamento riferimenti licenza e documentazione
-
-
**/

/**
- $Header: /usr/local/cvslocalrepository/SeamUtility/src/org/boco/seamUtility/converter/IntegerDummyConverter.java,v 1.2.4.3 2008/06/07 17:08:11 fab Exp $
- $Author: fab $
- $Revision: 1.2.4.3 $
- $Date: 2008/06/07 17:08:11 $
- $Log: IntegerDummyConverter.java,v $
- Revision 1.2.4.3  2008/06/07 17:08:11  fab
- Correzione di tutti DummyConverter
-
- Revision 1.2.4.2  2008/04/22 06:14:35  fab
- Aggiornamento indirizzo di posta
-
- Revision 1.2.4.1  2008/04/19 11:14:41  fab
- Aggiornamento riferimenti licenza e documentazione
-
- Revision 1.2  2008/01/08 11:33:28  fab
- Fix per evitare che nella stampa PDF compaia null nei campi vuoti
-
- Revision 1.1  2007/12/14 17:13:34  bob
- Aggiunti convertitori dummy
-
- Revision 1.2  2007/11/27 17:55:16  bob
- Fix sui validatori
-
- Revision 1.1  2007/09/30 07:45:40  fab
- Nuova versione iniziale del 30/09/2007
-
- Revision 1.1  2006/11/28 09:37:58  dev
- Spostati tutti i converter in un nuovo package
-
- Revision 1.1  2006/07/29 07:25:19  dev
- Versione Iniziale
-
**/
package org.boco.seamUtility.converter;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.ParseException;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import org.boco.seamUtility.messages.MessagesLoader;

public class IntegerDummyConverter implements Converter, Serializable
{
  private static final long  serialVersionUID  = 4776970214659972737L;
 
  public IntegerDummyConverter()
  {
    super();
  }

  public String getAsString(FacesContext facesContext, UIComponent component, Object obj)
  {
    if (obj == null)
    {
      return "";
    }

    String format = MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(), "Application_IntegerFormat", null, facesContext.getViewRoot().getLocale());   
    DecimalFormat  numberFormat = new DecimalFormat(format);   
   
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();

    dfs.setDecimalSeparator(MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(), "Application_DecimalSeparator", null, facesContext.getViewRoot().getLocale()).charAt(0));
    dfs.setGroupingSeparator(MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(), "Application_GroupingSeparator", null, facesContext.getViewRoot().getLocale()).charAt(0));

    numberFormat.setDecimalFormatSymbols(dfs);
   
    return numberFormat.format(obj);
  }

  public Object getAsObject(FacesContext facesContext, UIComponent component, String str) throws ConverterException
  {
    if (str == null || str.length() == 0)
    {
      return null;
    }

    try
    {
      String format = MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(), "Application_IntegerFormat", null, facesContext.getViewRoot().getLocale());   
      DecimalFormat  numberFormat = new DecimalFormat(format);   
     
      DecimalFormatSymbols dfs = new DecimalFormatSymbols();

      dfs.setDecimalSeparator(MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(), "Application_DecimalSeparator", null, facesContext.getViewRoot().getLocale()).charAt(0));
      dfs.setGroupingSeparator(MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(), "Application_GroupingSeparator", null, facesContext.getViewRoot().getLocale()).charAt(0));

      numberFormat.setDecimalFormatSymbols(dfs);

      return new Integer(numberFormat.parse(str).intValue());
    }
    catch (ParseException e)
    {
      String summary = MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(), "error_NotIntegerSummary", null, facesContext.getViewRoot().getLocale());
      String detail = MessagesLoader.getMessageResourceString(facesContext.getApplication().getMessageBundle(), "error_NotIntegerDetail", null, facesContext.getViewRoot().getLocale());

      FacesMessage message = new FacesMessage();
      message.setSummary(summary);
      message.setDetail(detail);
      message.setSeverity(FacesMessage.SEVERITY_ERROR);
      throw new ConverterException(message);
      //return null;
    }
  }
}
TOP

Related Classes of org.boco.seamUtility.converter.IntegerDummyConverter

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.