1 14 15 package com.sun.facelets.tag.jsf.core; 16 17 import java.util.TimeZone ; 18 19 import javax.el.ELException; 20 import javax.faces.FacesException; 21 import javax.faces.convert.Converter; 22 import javax.faces.convert.DateTimeConverter; 23 24 import com.sun.facelets.FaceletContext; 25 import com.sun.facelets.FaceletException; 26 import com.sun.facelets.tag.MetaRuleset; 27 import com.sun.facelets.tag.TagAttribute; 28 import com.sun.facelets.tag.TagAttributeException; 29 import com.sun.facelets.tag.jsf.ComponentSupport; 30 import com.sun.facelets.tag.jsf.ConvertHandler; 31 import com.sun.facelets.tag.jsf.ConverterConfig; 32 33 42 public final class ConvertDateTimeHandler extends ConvertHandler { 43 44 private final TagAttribute dateStyle; 45 46 private final TagAttribute locale; 47 48 private final TagAttribute pattern; 49 50 private final TagAttribute timeStyle; 51 52 private final TagAttribute timeZone; 53 54 private final TagAttribute type; 55 56 59 public ConvertDateTimeHandler(ConverterConfig config) { 60 super(config); 61 this.dateStyle = this.getAttribute("dateStyle"); 62 this.locale = this.getAttribute("locale"); 63 this.pattern = this.getAttribute("pattern"); 64 this.timeStyle = this.getAttribute("timeStyle"); 65 this.timeZone = this.getAttribute("timeZone"); 66 this.type = this.getAttribute("type"); 67 } 68 69 75 protected Converter createConverter(FaceletContext ctx) 76 throws FacesException, ELException, FaceletException { 77 return ctx.getFacesContext().getApplication().createConverter(DateTimeConverter.CONVERTER_ID); 78 79 } 80 81 87 protected void setAttributes(FaceletContext ctx, Object obj) { 88 DateTimeConverter c = (DateTimeConverter) obj; 89 if (this.locale != null) { 90 c.setLocale(ComponentSupport.getLocale(ctx, this.locale)); 91 } 92 if (this.pattern != null) { 93 c.setPattern(this.pattern.getValue(ctx)); 94 } else { 95 if (this.type != null) { 96 c.setType(this.type.getValue(ctx)); 97 } 98 if (this.dateStyle != null) { 99 c.setDateStyle(this.dateStyle.getValue(ctx)); 100 } 101 if (this.timeStyle != null) { 102 c.setTimeStyle(this.timeStyle.getValue(ctx)); 103 } 104 } 105 106 if (this.timeZone != null) { 107 Object t = this.timeZone.getObject(ctx); 108 if (t instanceof TimeZone ) { 109 c.setTimeZone((TimeZone ) t); 110 } else if (t instanceof String ) { 111 TimeZone tz = TimeZone.getTimeZone((String ) t); 112 c.setTimeZone(tz); 113 } else { 114 throw new TagAttributeException( 115 this.tag, 116 this.timeZone, 117 "Illegal TimeZone, must evaluate to either a java.util.TimeZone or String, is type: " 118 + t); 119 } 120 } 121 } 122 123 protected MetaRuleset createMetaRuleset(Class type) { 124 return super.createMetaRuleset(type).ignoreAll(); 125 } 126 } 127 | Popular Tags |