001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package org.apache.myfaces.tobago.component; 021 022 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FREQUENCY; 023 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_UPDATE; 024 025 import javax.faces.component.UIComponentBase; 026 import javax.faces.context.FacesContext; 027 import javax.faces.el.ValueBinding; 028 029 /* 030 * Date: 28.05.2006 031 * Time: 21:57:46 032 */ 033 public class UIReload extends UIComponentBase { 034 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Reload"; 035 public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.Reload"; 036 037 private Integer frequency; 038 039 private Boolean update; 040 041 private Boolean immediate; 042 043 public Object saveState(FacesContext context) { 044 Object[] values = new Object[4]; 045 values[0] = super.saveState(context); 046 values[1] = frequency; 047 values[2] = update; 048 values[3] = immediate; 049 return values; 050 } 051 052 public void restoreState(FacesContext context, Object savedState) { 053 Object[] values = (Object[]) savedState; 054 super.restoreState(context, values[0]); 055 frequency = (Integer) values[1]; 056 update = (Boolean) values[2]; 057 immediate = (Boolean) values[3]; 058 } 059 060 public int getFrequency() { 061 if (frequency != null) { 062 return frequency; 063 } 064 ValueBinding vb = getValueBinding(ATTR_FREQUENCY); 065 Integer value = null; 066 if (vb != null) { 067 value = (Integer) vb.getValue(getFacesContext()); 068 } 069 if (value != null) { 070 return value; 071 } else { 072 return 5000; 073 } 074 } 075 076 public void setFrequency(int frequency) { 077 this.frequency = frequency; 078 } 079 080 public void setUpdate(boolean update) { 081 this.update = update; 082 } 083 084 public boolean getUpdate() { 085 if (update != null) { 086 return update; 087 } 088 ValueBinding vb = getValueBinding(ATTR_UPDATE); 089 Boolean value = null; 090 if (vb != null) { 091 value = (Boolean) vb.getValue(getFacesContext()); 092 } 093 if (value != null) { 094 return value; 095 } else { 096 return true; 097 } 098 } 099 100 public void setImmediate(boolean immediate) { 101 this.immediate = immediate; 102 } 103 104 public boolean isImmediate() { 105 if (immediate != null) { 106 return immediate; 107 } 108 ValueBinding vb = getValueBinding("immediate"); 109 Boolean value = null; 110 if (vb != null) { 111 value = (Boolean) vb.getValue(getFacesContext()); 112 } 113 if (value != null) { 114 return value; 115 } else { 116 return false; 117 } 118 } 119 120 public String getFamily() { 121 return COMPONENT_FAMILY; 122 } 123 }