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 014 import org.apache.log4j.Logger; 015 016 import edu.nrao.sss.model.project.scan.ScanMode; 017 import edu.nrao.sss.webapp.faces.component.ScanIntentsUIComponent; 018 019 public class ScanIntentsTag extends UIComponentTag 020 { 021 private static final Logger log = Logger.getLogger(ScanIntentsTag.class); 022 023 public String getComponentType() { return "edu.nrao.sss.ScanIntent"; } 024 public String getRendererType() { return null; } 025 026 private String value = null, 027 valueChangeListener = null, 028 scanMode = null, 029 enabled = null, 030 style = null, 031 styleClass = null; 032 033 @SuppressWarnings("unchecked") 034 protected void setProperties(UIComponent component) 035 { 036 super.setProperties(component); 037 038 FacesContext context = FacesContext.getCurrentInstance(); 039 Application app = context.getApplication(); 040 041 log.debug("Value is: " + value); 042 if (value != null) 043 { 044 if (isValueReference(value)) 045 { 046 ValueBinding vb = app.createValueBinding(value); 047 048 component.setValueBinding("value", vb); 049 } 050 051 else 052 { 053 throw new ReferenceSyntaxException(value + " is not a valid EL expression"); 054 } 055 } 056 057 058 if (scanMode != null) 059 { 060 if (isValueReference(scanMode)) 061 { 062 ValueBinding vb = app.createValueBinding(scanMode); 063 064 component.setValueBinding("scanMode", vb); 065 } 066 067 else 068 { 069 ScanMode sm = ScanMode.valueOf(scanMode); 070 ((ScanIntentsUIComponent)component).setScanMode(sm); 071 } 072 } 073 074 if (valueChangeListener != null) 075 { 076 Class[] params = new Class[1]; 077 params[0] = ValueChangeEvent.class; 078 079 MethodBinding mb = app.createMethodBinding(valueChangeListener, params); 080 081 ((UIInput)component).setValueChangeListener(mb); 082 } 083 084 if (enabled != null) 085 { 086 if (isValueReference(enabled)) 087 { 088 ValueBinding vb = app.createValueBinding(enabled); 089 090 component.setValueBinding("enabled", vb); 091 } 092 093 else 094 { 095 ((ScanIntentsUIComponent)component).setEnabled(isTrue(enabled)); 096 } 097 } 098 099 if (style != null) 100 { 101 if (isValueReference(style)) 102 { 103 ValueBinding vb = app.createValueBinding(style); 104 105 component.setValueBinding("style", vb); 106 } 107 108 else 109 { 110 component.getAttributes().put("style", style); 111 } 112 } 113 114 if (styleClass != null) 115 { 116 if (isValueReference(styleClass)) 117 { 118 ValueBinding vb = app.createValueBinding(styleClass); 119 120 component.setValueBinding("styleClass", vb); 121 } 122 123 else 124 { 125 component.getAttributes().put("styleClass", styleClass); 126 } 127 } 128 } 129 130 public void release() 131 { 132 super.release(); 133 this.enabled = null; 134 this.value = null; 135 this.style = null; 136 this.styleClass = null; 137 this.scanMode = null; 138 } 139 140 public void setValue(String v) 141 { 142 this.value = v; 143 } 144 145 public void setMode(String m) 146 { 147 this.scanMode = m; 148 } 149 150 public void setValueChangeListener(String l) 151 { 152 this.valueChangeListener = l; 153 } 154 155 public void setEnabled(String e) 156 { 157 this.enabled = e; 158 } 159 160 public void setStyle(String s) 161 { 162 this.style = s; 163 } 164 165 public void setStyleClass(String sc) 166 { 167 this.styleClass = sc; 168 } 169 170 public boolean isTrue(String v) 171 { 172 return ("true".equalsIgnoreCase(v) || "1".equals(v)); 173 } 174 }