001    package edu.nrao.sss.webapp.faces.tag;
002    
003    import javax.faces.application.Application;
004    import javax.faces.component.UIComponent;
005    import javax.faces.component.UIData;
006    import javax.faces.webapp.UIComponentTag;
007    import javax.faces.el.ValueBinding;
008    import javax.faces.el.ReferenceSyntaxException;
009    
010    import javax.faces.context.FacesContext;
011    
012    //import org.apache.log4j.Logger;
013    
014    public class ForEachTag extends UIComponentTag 
015    {
016            //private Logger log = Logger.getLogger(ForEachTag.class);
017    
018            private String value = null, var = 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.ForEach"; }
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 value
035                    if (value != null) 
036                    { 
037                            //log.debug("Setting value to: " + value);
038                            if (isValueReference(value))
039                            {
040                                    ValueBinding vb = app.createValueBinding(value);
041    
042                                    component.setValueBinding("value", vb);                  
043                            }
044                            else 
045                            {
046                                    throw new ReferenceSyntaxException(value + " is not a valid EL expression");
047                            }
048                    }                         
049                    
050                    if (var != null) 
051                    { 
052                            if (isValueReference(var))
053                            {
054                                    ValueBinding vb = app.createValueBinding(var);
055    
056                                    component.setValueBinding("var", vb);
057                            }
058                            
059                            else
060                            {
061                                    //log.debug("Setting var to : " + var);
062                                    ((UIData)component).setVar(var);
063                            }
064                    }
065            }
066    
067            /**
068              * clear up any resources we've used.
069              */
070            public void release()
071            {
072                    super.release();
073                    value = null;
074                    var = null;
075            }
076    
077    
078            /**
079              * Bean method for our value attribute.
080              */
081            public void setValue(String value)
082            {
083                    this.value = value;
084            } 
085    
086            /**
087              * Bean method for our var attribute.
088              */
089            public void setVar(String var)
090            {
091                    this.var = var;
092            } 
093    }