Package javax.faces.convert

Examples of javax.faces.convert.DateTimeConverter$Type


        try {
            ValueExpression ve = getValueExpression("currentDate");
            if (ve != null) {
                ELContext elContext = facesContext.getELContext();
                if (ve.getType(elContext).equals(String.class)) {
                    DateTimeConverter convert = new DateTimeConverter();
                    convert.setLocale(CalendarHelper.getAsLocale(facesContext, this, getLocale()));
                    convert.setPattern(CalendarHelper.getDatePatternOrDefault(this));
                    ve.setValue(facesContext.getELContext(), convert.getAsString(facesContext, this, currentDate));
                    return;
                } else if (ve.getType(elContext).equals(Calendar.class)) {
                    Calendar c = CalendarHelper.getCalendar(facesContext, this);
                    c.setTime((Date) currentDate);
                    ve.setValue(elContext, c);
View Full Code Here


        if (converter == null || calendar == null) {
            return null;
        }

        if (converter instanceof DateTimeConverter) {
            DateTimeConverter defaultConverter = (DateTimeConverter) converter;
            defaultConverter.setPattern(CalendarHelper.getDatePatternOrDefault(calendar));
            defaultConverter.setLocale(CalendarHelper.getAsLocale(facesContext, calendar));
            defaultConverter.setTimeZone(CalendarHelper.getTimeZoneOrDefault(calendar));
        }
        return converter;
    }
View Full Code Here

        assertNotNull("out1 converter", out1.getConverter());
        assertNotNull("out2 converter", out2.getConverter());
        assertNotNull("out3 converter", out3.getConverter());
        assertNotNull("out4 converter", out4.getConverter());
        assertNotNull("out5 converter", out5.getConverter());
        DateTimeConverter converter6 = (DateTimeConverter)out6.getConverter();

        assertEquals("out1 value", "12/24/69", out1.getConverter().getAsString(
                faces, out1, now));
        assertEquals("out2 value", "12/24/69 6:57:12 AM", out2.getConverter()
                .getAsString(faces, out2, now));
        assertEquals("out3 value", "Dec 24, 1969", out3.getConverter()
                .getAsString(faces, out3, now));
        assertEquals("out4 value", "6:57:12 AM", out4.getConverter()
                .getAsString(faces, out4, now));
        assertEquals("out5 value", "0:57 AM, CST", out5.getConverter()
                .getAsString(faces, out5, now));
        assertEquals("Timezone should be GMT", TimeZone.getTimeZone("GMT"), converter6.getTimeZone());
    }
View Full Code Here

     *
     * @see org.apache.myfaces.view.facelets.tag.ObjectHandler#setAttributes(javax.faces.view.facelets.FaceletContext, java.lang.Object)
     */
    public void setAttributes(FaceletContext ctx, Object obj)
    {
        DateTimeConverter c = (DateTimeConverter) obj;
        if (this.locale != null)
        {
            c.setLocale(ComponentSupport.getLocale(ctx, this.locale));
        }
        if (this.pattern != null)
        {
            c.setPattern(this.pattern.getValue(ctx));
        }
        else
        {
            if (this.type != null)
            {
                c.setType(this.type.getValue(ctx));
            }
            if (this.dateStyle != null)
            {
                c.setDateStyle(this.dateStyle.getValue(ctx));
            }
            if (this.timeStyle != null)
            {
                c.setTimeStyle(this.timeStyle.getValue(ctx));
            }
        }

        if (this.timeZone != null)
        {
            Object t = this.timeZone.getObject(ctx);
            if (t != null)
            {
                if (t instanceof TimeZone)
                {
                    c.setTimeZone((TimeZone) t);
                }
                else if (t instanceof String)
                {
                    TimeZone tz = TimeZone.getTimeZone((String) t);
                    c.setTimeZone(tz);
                }
                else
                {
                    throw new TagAttributeException(this.tag, this.timeZone,
                                                    "Illegal TimeZone, must evaluate to either a java.util.TimeZone or String, is type: "
View Full Code Here

    Converter converter = super.getConverter();
    if (converter == null) {
      // setting required default converter
      Application application
          = FacesContext.getCurrentInstance().getApplication();
      DateTimeConverter dateTimeConverter
          = (DateTimeConverter) application.createConverter(CONVERTER_ID);
      dateTimeConverter.setPattern("HH:mm");
      dateTimeConverter.setTimeZone(TimeZone.getDefault());
      setConverter(dateTimeConverter);
    }
    return converter;
  }
View Full Code Here

    // for convenience, we will set the time zone of the converter to that
    // specified by the context or, if that is not present, to the time zone
    // of the server
    if (converter instanceof DateTimeConverter)
    {
      DateTimeConverter dtc = (DateTimeConverter) converter;
     
      boolean trinidadDTC = _isTrinidadDateTimeConverter(converter);
     
      if (!trinidadDTC)
      {
        // if it is not the Trinidad DateTimeConverter, set the date style to
        // short
        dtc.setDateStyle("short");
      }
     
      // if it is not the Trinidad DateTimeConverter or (it is AND
      // no time zone is set) then we want to set the
      // time zone to the one in the faces context or use
      // the default server time zone on the converter
      if (!trinidadDTC || dtc.getTimeZone() == null)
      {
        TimeZone tz = null;
       
        RequestContext requestContext = RequestContext.getCurrentInstance();
        tz = requestContext.getTimeZone();
        if(tz == null)
        {
          tz = TimeZone.getDefault();
        }
       
        dtc.setTimeZone(tz);
      }
    }
   
    return converter;
  }
View Full Code Here

   * @param calendar - calendar component
   *
   * @return created converter
   */
  protected static Converter createDefaultConverter() {
      return new DateTimeConverter();
  }
View Full Code Here

      if(converter == null) {
    return null;
      }
     
      if(converter instanceof DateTimeConverter) {
    DateTimeConverter defaultConverter = (DateTimeConverter) converter;
    defaultConverter.setPattern(calendar.getDatePattern());
    defaultConverter.setLocale(calendar.getAsLocale(calendar.getLocale()));
    defaultConverter.setTimeZone(calendar.getTimeZone());
      }
     
      return converter;
  }
View Full Code Here

  }

  public Date getConvertedValue(FacesContext context, String currentDateString)
      throws ConverterException {

    DateTimeConverter datetime = new DateTimeConverter();
    datetime.setPattern("m/y");
    Date newCurrentDate = (Date) datetime.getAsObject(context, this,
        currentDateString);
    return newCurrentDate;
  }
View Full Code Here

    try {
      ValueExpression ve = getValueExpression("currentDate");
      if (ve != null) {
            ELContext elContext = context.getELContext();
            if (ve.getType(elContext).equals(String.class)) {
          DateTimeConverter convert = new DateTimeConverter();
          convert.setLocale(getAsLocale(getLocale()));
          convert.setPattern(getDatePattern());
          ve.setValue(context.getELContext(), convert.getAsString(context, this,
              currentDate));
          return;
        } else if (ve.getType(elContext).equals(Calendar.class)) {
          Calendar c = Calendar.getInstance();
          c.setTime((Date) currentDate);
View Full Code Here

TOP

Related Classes of javax.faces.convert.DateTimeConverter$Type

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.