001 package edu.nrao.sss.webapp.faces.tag; 002 003 import javax.faces.webapp.UIComponentTag; 004 import javax.faces.component.UIComponent; 005 import javax.faces.component.UIInput; 006 import javax.faces.context.FacesContext; 007 import javax.faces.application.Application; 008 import javax.faces.el.ValueBinding; 009 import javax.faces.el.MethodBinding; 010 import javax.faces.el.ReferenceSyntaxException; 011 import javax.faces.event.ValueChangeEvent; 012 013 import org.apache.log4j.Logger; 014 015 import edu.nrao.sss.webapp.faces.component.TimeIntervalUIComponent; 016 017 public class TimeIntervalTag extends UIComponentTag 018 { 019 private static final Logger log = Logger.getLogger(TimeIntervalTag.class); 020 021 public String getComponentType() { return "edu.nrao.sss.TimeInterval"; } 022 public String getRendererType() { return null; } 023 024 private String value = null, 025 valueChangeListener = null, 026 enabled = null, 027 style = null, 028 styleClass = null; 029 030 @SuppressWarnings("unchecked") 031 protected void setProperties(UIComponent component) 032 { 033 super.setProperties(component); 034 035 FacesContext context = FacesContext.getCurrentInstance(); 036 Application app = context.getApplication(); 037 038 log.debug("Value is: " + value); 039 if (value != null) 040 { 041 if (isValueReference(value)) 042 { 043 ValueBinding vb = app.createValueBinding(value); 044 045 component.setValueBinding("value", vb); 046 } 047 048 else 049 { 050 throw new ReferenceSyntaxException(value + " is not a valid EL expression"); 051 } 052 } 053 054 if (valueChangeListener != null) 055 { 056 Class[] params = new Class[1]; 057 params[0] = ValueChangeEvent.class; 058 059 MethodBinding mb = app.createMethodBinding(valueChangeListener, params); 060 061 ((UIInput)component).setValueChangeListener(mb); 062 } 063 064 if (enabled != null) 065 { 066 log.debug("Enabled flag was: " + enabled); 067 if (isValueReference(enabled)) 068 { 069 ValueBinding vb = app.createValueBinding(enabled); 070 071 component.setValueBinding("enabled", vb); 072 } 073 074 else 075 { 076 ((TimeIntervalUIComponent)component).setEnabled(isTrue(enabled)); 077 } 078 } 079 080 if (style != null) 081 { 082 if (isValueReference(style)) 083 { 084 ValueBinding vb = app.createValueBinding(style); 085 086 component.setValueBinding("style", vb); 087 } 088 089 else 090 { 091 component.getAttributes().put("style", style); 092 } 093 } 094 095 if (styleClass != null) 096 { 097 if (isValueReference(styleClass)) 098 { 099 ValueBinding vb = app.createValueBinding(styleClass); 100 101 component.setValueBinding("styleClass", vb); 102 } 103 104 else 105 { 106 component.getAttributes().put("styleClass", styleClass); 107 } 108 } 109 } 110 111 public void setValue(String v) 112 { 113 this.value = v; 114 } 115 116 public void setValueChangeListener(String l) 117 { 118 this.valueChangeListener = l; 119 } 120 121 public void setEnabled(String e) 122 { 123 this.enabled = e; 124 } 125 126 public void setStyle(String s) 127 { 128 this.style = s; 129 } 130 131 public void setStyleClass(String sc) 132 { 133 this.styleClass = sc; 134 } 135 136 public boolean isTrue(String v) 137 { 138 return ("true".equalsIgnoreCase(v) || "1".equals(v)); 139 } 140 }