001 package edu.nrao.sss.webapp.faces.tag; 002 003 import javax.faces.application.Application; 004 import javax.faces.webapp.UIComponentTag; 005 import javax.faces.component.UIComponent; 006 import javax.faces.el.ValueBinding; 007 import javax.faces.context.FacesContext; 008 009 import edu.nrao.sss.webapp.faces.component.IfUIComponent; 010 011 /** 012 * This class connects the JSF <code>if</code> tag to the IfUIComponent. 013 * @author btruitt 014 * @see edu.nrao.sss.webapp.faces.component.IfUIComponent 015 */ 016 public class IfTag extends UIComponentTag 017 { 018 private String test = null; 019 020 // Associate the renderer and component type. Same type as recorded in 021 // faces-config.xml. 022 public String getComponentType() { return "edu.nrao.sss.If"; } 023 public String getRendererType() { return null; } 024 025 026 @SuppressWarnings("unchecked") 027 protected void setProperties(UIComponent component) 028 { 029 super.setProperties(component); 030 031 FacesContext context = FacesContext.getCurrentInstance(); 032 Application app = context.getApplication(); 033 034 // set test as the rendered attribute of our IfComponent 035 if (test != null) 036 { 037 if (isValueReference(test)) 038 { 039 ValueBinding vb = app.createValueBinding(test); 040 component.setValueBinding("test", vb); 041 } 042 else 043 { 044 ((IfUIComponent)component).setTest(Boolean.valueOf(this.test)); 045 } 046 } 047 } 048 049 /** 050 * clear up any resources we've used. 051 */ 052 public void release() 053 { 054 super.release(); 055 test = null; 056 } 057 058 059 /** 060 * Bean method for our test attribute. 061 */ 062 public void setTest(String test) 063 { 064 this.test = test; 065 } 066 }