summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2007-04-02 21:46:04 +0000
committerxue <>2007-04-02 21:46:04 +0000
commit571b069953f559edd02f89476ebe628efa63d613 (patch)
tree3db21262d2f66bde4e9dfb551a91746fe1463a7d
parentc391fe9f888c8b4cb3465bd1e535398ae3599283 (diff)
Reduced ViewState size significantly by ignoring initial property values set in template
-rw-r--r--HISTORY1
-rw-r--r--framework/Web/UI/TControl.php55
-rw-r--r--framework/Web/UI/TTemplateManager.php7
3 files changed, 52 insertions, 11 deletions
diff --git a/HISTORY b/HISTORY
index 4913dd1c..9de3a5af 100644
--- a/HISTORY
+++ b/HISTORY
@@ -35,6 +35,7 @@ ENH: Ticket#561 - Powered by PRADO image to become an asset (Qiang)
ENH: Ticket#569 - Added TTextBox.PersistPassword property (Qiang)
ENH: Ticket#571 - Made TPage.ClientSupportsJavaScript property writable (Qiang)
ENH: Ticket#575 - Made TAuthManager.ReturnUrl property writable (Qiang)
+ENH: Reduced ViewState size significantly by ignoring initial property values set in template (Qiang)
ENH: Added PRADO_CHMOD constant so that users can specify the permission of PRADO-created directories (Qiang)
ENH: Added Display property to TWebControl (Wei)
ENH: Added TUser.getState() and setState() for storing user session data (Qiang)
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 68e10c6e..5a8824d3 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -131,28 +131,36 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
/**
* @var string control unique ID
*/
- private $_uid=null;
+ private $_uid;
/**
* @var TControl parent of the control
*/
- private $_parent=null;
+ private $_parent;
/**
* @var TPage page that the control resides in
*/
- private $_page=null;
+ private $_page;
/**
* @var TControl naming container of the control
*/
- private $_namingContainer=null;
+ private $_namingContainer;
/**
* @var TTemplateControl control whose template contains the control
*/
- private $_tplControl=null;
+ private $_tplControl;
/**
- * @var TMap viewstate data
+ * @var array viewstate data
*/
private $_viewState=array();
/**
+ * @var array temporary state (usually set in template)
+ */
+ private $_tempState=array();
+ /**
+ * @var boolean whether we should keep state in viewstate
+ */
+ private $_trackViewState=true;
+ /**
* @var integer the current stage of the control lifecycles
*/
private $_stage=0;
@@ -704,6 +712,17 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
}
/**
+ * Sets a value indicating whether we should keep data in viewstate.
+ * When it is false, data saved via setViewState() will not be persisted.
+ * By default, it is true, meaning data will be persisted across postbacks.
+ * @param boolean whether data should be persisted
+ */
+ public function trackViewState($enabled)
+ {
+ $this->_trackViewState=TPropertyValue::ensureBoolean($enabled);
+ }
+
+ /**
* Returns a viewstate value.
*
* This function is very useful in defining getter functions for component properties
@@ -714,7 +733,16 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
*/
public function getViewState($key,$defaultValue=null)
{
- return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue;
+ if(isset($this->_viewState[$key]))
+ return $this->_viewState[$key]!==null?$this->_viewState[$key]:$defaultValue;
+ else if(isset($this->_tempState[$key]))
+ {
+ if(is_object($this->_tempState[$key]) && $this->_trackViewState)
+ $this->_viewState[$key]=$this->_tempState[$key];
+ return $this->_tempState[$key];
+ }
+ else
+ return $defaultValue;
}
/**
@@ -729,10 +757,16 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
*/
public function setViewState($key,$value,$defaultValue=null)
{
- if($value===$defaultValue)
- unset($this->_viewState[$key]);
- else
+ if($this->_trackViewState)
+ {
$this->_viewState[$key]=$value;
+ unset($this->_tempState[$key]);
+ }
+ else
+ {
+ unset($this->_viewState[$key]);
+ $this->_tempState[$key]=$value;
+ }
}
/**
@@ -742,6 +776,7 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
public function clearViewState($key)
{
unset($this->_viewState[$key]);
+ unset($this->_tempState[$key]);
}
/**
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php
index d71662ca..286aa252 100644
--- a/framework/Web/UI/TTemplateManager.php
+++ b/framework/Web/UI/TTemplateManager.php
@@ -342,10 +342,15 @@ class TTemplate extends TApplicationComponent implements ITemplate
$component->setSkinID($properties['skinid']);
unset($properties['skinid']);
}
+
+ $component->trackViewState(false);
+
$component->applyStyleSheetSkin($page);
- // apply attributes
foreach($properties as $name=>$value)
$this->configureControl($component,$name,$value);
+
+ $component->trackViewState(true);
+
if($parent===$tplControl)
$directChildren[]=$component;
else