1 25 26 29 30 package net.killingar.webwork.view.taglib; 31 32 import javax.servlet.jsp.JspException ; 33 import javax.servlet.jsp.JspTagException ; 34 import java.text.SimpleDateFormat ; 35 import java.util.Date ; 36 37 public class DateTag extends webwork.view.taglib.WebWorkTagSupport 38 { 39 protected String valueAttr; 41 protected String formatting; protected SimpleDateFormat formatter = new SimpleDateFormat (); 44 public void setValue(String inName) { valueAttr = inName; } 46 public void setFormat(String inFormatting) { formatting = inFormatting; formatter = new SimpleDateFormat (formatting); } 47 48 public int doStartTag() throws JspException 50 { 51 try 52 { 53 Date value = (Date )findValue(valueAttr); 54 55 if (value != null) 56 { 57 if (formatting != null) 58 { 59 formatter.applyPattern(formatting); 60 pageContext.getOut().write(formatter.format(value)); 61 } 62 else 63 { 64 pageContext.getOut().write(net.killingar.Utils.formatShortDate(value, " ")); 65 } 66 } 67 } 68 catch (Exception e) 69 { 70 e.printStackTrace(); 71 throw new JspTagException ("Could not show value " + valueAttr + ":" + e); 72 } 73 74 return SKIP_BODY; 75 } 76 } | Popular Tags |