Package javax.faces.convert

Examples of javax.faces.convert.NumberConverter


        setConverterIdString(NumberConverter.CONVERTER_ID);
    }

    protected Converter createConverter() throws JspException
    {
        NumberConverter converter = (NumberConverter) super.createConverter();
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        if (null != _currencyCode)
        {
            converter.setCurrencyCode(
                    (String) UIComponentELTagUtils.evaluateValueExpression(elContext, _currencyCode));
        }
        if (null != _currencySymbol)
        {
            converter.setCurrencySymbol(
                    (String) UIComponentELTagUtils.evaluateValueExpression(elContext, _currencySymbol));
        }
        if (null != _groupingUsed)
        {
            converter.setGroupingUsed(UIComponentELTagUtils.getBooleanValue(elContext, _groupingUsed));
        } else
        {
            converter.setGroupingUsed(true);
        }
        if (null != _integerOnly)
        {
            converter.setIntegerOnly(UIComponentELTagUtils.getBooleanValue(elContext, _integerOnly));
        } else
        {
            converter.setIntegerOnly(false);
        }
        if (null != _locale)
        {
            Locale locale;
            if (_locale.isLiteralText())
            {
                locale = new Locale(_locale.getExpressionString());
            } else
            {
                locale = (Locale) _locale.getValue(elContext);
                if (null == locale)
                {
                    locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
                }
            }
            converter.setLocale(locale);
        }
        if (null != _maxFractionDigits)
        {
            converter.setMaxFractionDigits(UIComponentELTagUtils.getIntegerValue(elContext, _maxFractionDigits));
        }
        if (null != _maxIntegerDigits)
        {
            converter.setMaxIntegerDigits(UIComponentELTagUtils.getIntegerValue(elContext, _maxIntegerDigits));
        }
        if (null != _minFractionDigits)
        {
            converter.setMinFractionDigits(UIComponentELTagUtils.getIntegerValue(elContext, _minFractionDigits));
        }
        if (null != _minIntegerDigits)
        {
            converter.setMinIntegerDigits(UIComponentELTagUtils.getIntegerValue(elContext, _minIntegerDigits));
        }
        if (null != _pattern)
        {
            converter.setPattern((String) UIComponentELTagUtils.evaluateValueExpression(elContext, _pattern));
        }
        if (null != _type)
        {
            converter.setType((String) UIComponentELTagUtils.evaluateValueExpression(elContext, _type));
        } else
        {
            converter.setType("number");
        }
        return converter;
    }
View Full Code Here


    }

    private void setUpConverter(Slider slider) {
        Converter converter = slider.getConverter();
        if (converter == null) {
            NumberConverter numberConverter = new NumberConverter();
            slider.setConverter(numberConverter);
        }
    }
View Full Code Here

        double minTick = slider.getMinorTickSpacing().doubleValue();
        double maxTick = slider.getMajorTickSpacing().doubleValue();
        NumberFormat format = NumberFormat.getInstance(context.getViewRoot().getLocale());
        format.setMinimumFractionDigits(0);
        format.setMaximumFractionDigits(2);
        NumberConverter converter = getNumberConverter(context, slider);

        double curTick = minValue;
        if (slider.isTicksLabelsVisible() || slider.isTicksVisible()) {
            for (int counterTicks = 0; curTick <= maxValue; counterTicks++) {
                writer.startElement("div", slider);
View Full Code Here

        return (NumberConverter) converter;
    }

    private JSONObject createFormatOptions(FacesContext context, Slider slider)
            throws JSONException, IOException {
        NumberConverter numberConverter = getNumberConverter(context, slider);
        JSONObject options = new JSONObject();
        options.put("currency", numberConverter.getCurrencyCode());
        options.put("locale", numberConverter.getLocale().toString());
        options.put("pattern", numberConverter.getPattern());
        options.put("round", numberConverter.getMaxFractionDigits());
        options.put("symbol", numberConverter.getCurrencySymbol());
        options.put("type", numberConverter.getType());

        JSONObject customs = Resources.getNumberFormatSettings(numberConverter.getLocale());
        options.put("customs", customs);
        return options;
    }
View Full Code Here

    }

    private void setUpConverter(Spinner spinner) {
        Converter converter = spinner.getConverter();
        if (converter == null) {
            NumberConverter numberConverter = new NumberConverter();
            spinner.setConverter(numberConverter);
        }
    }
View Full Code Here

        if (!(converter instanceof NumberConverter)) {
            throw new FacesException("Unsupported converter class of <o:spinner> with id " + spinner.getClientId(context) +
                    " : " + converter.getClass().getName());
        }

        NumberConverter numberConverter = (NumberConverter) converter;

        JSONObject options = new JSONObject();
        options.put("currency", numberConverter.getCurrencyCode());
        options.put("locale", numberConverter.getLocale().toString());
        options.put("pattern", numberConverter.getPattern());
        options.put("round", 10);
        options.put("symbol", numberConverter.getCurrencySymbol());
        options.put("type", numberConverter.getType());


        JSONObject customs = Resources.getNumberFormatSettings(numberConverter.getLocale());
        options.put("customs", customs);
        return options;
    }  
View Full Code Here

    UIComponent component = (UIComponent) mock.proxy();
    //we do not care about getValueExpression() being called or not
    mock.stubs().method("getValueExpression");

    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
    NumberConverter converter = getNumberConverter();

    doTestNullContext(wrapper, converter);
  }
View Full Code Here

    doTestNullContext(wrapper, converter);
  }

  public void testNullComponent()
  {
    NumberConverter converter  = getNumberConverter();

    doTestNullComponent(facesContext, converter);
  }
View Full Code Here

    UIComponent component = (UIComponent) mock.proxy();
    //we do not care about getValueExpression() being called or not
    mock.stubs().method("getValueExpression");

    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
    NumberConverter converter  = getNumberConverter();

    doTestNull(facesContext, wrapper, converter);
  }
View Full Code Here

    setFacesContext(facesContext);
    try
    {
      String input = "123";
      NumberConverter converter = getNumberConverter();
      Object number = converter.getAsObject(facesContext, component, input);
      assertEquals(true, number instanceof Number);
      assertEquals(true, (((Number)number).intValue() == 123));

      String outVal = converter.getAsString(facesContext, component, number);
      assertEquals(input, outVal);
    }
    finally
    {
      setFacesContext(null);
View Full Code Here

TOP

Related Classes of javax.faces.convert.NumberConverter

Copyright © 2018 www.massapicom. 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.