001 package edu.nrao.sss.webapp.faces.tag; 002 003 import edu.nrao.sss.webapp.faces.component.ExitDialogUIComponent; 004 005 import javax.faces.component.UIComponent; 006 import javax.faces.context.FacesContext; 007 import javax.faces.application.Application; 008 import javax.faces.el.ValueBinding; 009 010 /** 011 * Tag for {@link ExitDialogUIComponent}. Adds the submittedChanges attribute. 012 */ 013 public class ExitDialogTag extends FloatingDialogTag 014 { 015 public String getComponentType() { return "edu.nrao.sss.ExitDialog"; } 016 public String getRendererType() { return null; } 017 018 private String submittedChanges = null; 019 020 @SuppressWarnings("unchecked") 021 protected void setProperties(UIComponent component) 022 { 023 super.setProperties(component); 024 025 FacesContext context = FacesContext.getCurrentInstance(); 026 Application app = context.getApplication(); 027 028 if (submittedChanges != null) 029 { 030 if (isValueReference(submittedChanges)) 031 { 032 ValueBinding vb = app.createValueBinding(submittedChanges); 033 034 component.setValueBinding("submittedChanges", vb); 035 } 036 037 else 038 { 039 //The logic is reversed here so that if the value is garbage or 040 //invalid, it defaults to true. This is safer than possibly loosing 041 //data. 042 ((ExitDialogUIComponent)component).setHasSubmittedChanges(!isFalse(submittedChanges)); 043 } 044 } 045 } 046 047 public void release() 048 { 049 super.release(); 050 this.submittedChanges = null; 051 } 052 053 public void setSubmittedChanges(String e) 054 { 055 this.submittedChanges = e; 056 } 057 058 public boolean isFalse(String v) 059 { 060 return ("false".equalsIgnoreCase(v) || "0".equals(v)); 061 } 062 }