diff options
Diffstat (limited to 'framework/Web/UI/WebControls')
-rw-r--r-- | framework/Web/UI/WebControls/TDataBoundControl.php | 5 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TListControl.php | 19 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TRepeater.php | 36 |
3 files changed, 49 insertions, 11 deletions
diff --git a/framework/Web/UI/WebControls/TDataBoundControl.php b/framework/Web/UI/WebControls/TDataBoundControl.php index 7d865e0f..ea2a0602 100644 --- a/framework/Web/UI/WebControls/TDataBoundControl.php +++ b/framework/Web/UI/WebControls/TDataBoundControl.php @@ -40,6 +40,7 @@ abstract class TDataBoundControl extends TWebControl private $_currentDataSourceValid=false;
private $_currentViewIsFromDataSourceID=false;
private $_parameters=null;
+ private $_isDataBound=false;
/**
* @return Traversable data source object, defaults to null.
@@ -131,7 +132,7 @@ abstract class TDataBoundControl extends TWebControl */
protected function getIsDataBound()
{
- return $this->getViewState('IsDataBound',false);
+ return $this->_isDataBound;
}
/**
@@ -139,7 +140,7 @@ abstract class TDataBoundControl extends TWebControl */
protected function setIsDataBound($value)
{
- $this->setViewState('IsDataBound',TPropertyValue::ensureBoolean($value),false);
+ $this->_isDataBound=$value;
}
/**
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php index f5619b45..7057e119 100644 --- a/framework/Web/UI/WebControls/TListControl.php +++ b/framework/Web/UI/WebControls/TListControl.php @@ -80,7 +80,10 @@ abstract class TListControl extends TDataBoundControl * @var TListItemCollection item list
*/
private $_items=null;
-
+ /**
+ * @var boolean whether items are restored from viewstate
+ */
+ private $_loadedFromState=false;
/**
* @return string tag name of the list control
*/
@@ -137,7 +140,8 @@ abstract class TListControl extends TDataBoundControl */
public function addParsedObject($object)
{
- if($object instanceof TListItem)
+ // Do not add items from template if items are loaded from viewstate
+ if(!$this->_loadedFromState && ($object instanceof TListItem))
$this->getItems()->add($object);
}
@@ -190,14 +194,19 @@ abstract class TListControl extends TDataBoundControl }
/**
- * Loads items into from viewstate.
+ * Loads items from viewstate.
* This method is invoked right after control state is loaded.
* @param mixed event parameter
*/
protected function onLoadState($param)
{
- $this->_items=new TListItemCollection;
- $this->_items->loadState($this->getViewState('Items',null));
+ $this->_loadedFromState=true;
+ if(!$this->getIsDataBound())
+ {
+ $this->_items=new TListItemCollection;
+ $this->_items->loadState($this->getViewState('Items',null));
+ }
+ $this->clearViewState('Items');
}
/**
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php index 5110cc75..342a764b 100644 --- a/framework/Web/UI/WebControls/TRepeater.php +++ b/framework/Web/UI/WebControls/TRepeater.php @@ -56,6 +56,10 @@ class TRepeater extends TDataBoundControl implements INamingContainer private $_footer=null;
private static $_templates=array();
+ public function addParsedObject($object)
+ {
+ }
+
/**
* @return string the template string for the item
*/
@@ -227,8 +231,8 @@ class TRepeater extends TDataBoundControl implements INamingContainer self::$_templates[$key]=$template;
}
}
- $template->instantiateIn($item,$this->getPage());
$this->getControls()->add($item);
+ $template->instantiateIn($item);
}
}
@@ -250,14 +254,14 @@ class TRepeater extends TDataBoundControl implements INamingContainer return $item;
}
- protected function createChildControls()
+ protected function restoreItemsFromViewState()
{
$this->getControls()->clear();
$items=$this->getItems();
$items->clear();
$this->_header=null;
$this->_footer=null;
- if(($itemCount=$this->getViewState('ItemCount',null))!==null)
+ if(($itemCount=$this->getViewState('ItemCount',0))>0)
{
if($this->_headerTemplate!=='')
$this->_header=$this->createItemInternal(-1,'Header',false,null);
@@ -276,6 +280,31 @@ class TRepeater extends TDataBoundControl implements INamingContainer }
/**
+ * Saves items into viewstate.
+ * This method is invoked right before control state is to be saved.
+ * @param mixed event parameter
+ */
+ protected function onSaveState($param)
+ {
+ if($this->_items)
+ $this->setViewState('ItemCount',$this->_items->getCount(),0);
+ else
+ $this->clearViewState('ItemCount');
+ }
+
+ /**
+ * Loads items into from viewstate.
+ * This method is invoked right after control state is loaded.
+ * @param mixed event parameter
+ */
+ protected function onLoadState($param)
+ {
+ if(!$this->getIsDataBound())
+ $this->restoreItemsFromViewState();
+ $this->clearViewState('ItemCount');
+ }
+
+ /**
* Performs databinding to populate list items from data source.
* This method is invoked by dataBind().
* You may override this function to provide your own way of data population.
@@ -307,7 +336,6 @@ class TRepeater extends TDataBoundControl implements INamingContainer }
else
$this->setViewState('ItemCount',$itemIndex,-1);
- $this->setChildControlsCreated(true);
}
/**
|