summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorwei <>2006-09-15 23:49:56 +0000
committerwei <>2006-09-15 23:49:56 +0000
commitb196ea0e2e9ab9078022e88326edecf1ba5b2f9f (patch)
tree3d9f37bfa14c363fc91df306b798ddc1b7ef872e /framework
parent9f2905f5e2a6d0ab33e4e2d82162183cfd63a042 (diff)
Defer render() calls in callback event handler to a later stage.
Diffstat (limited to 'framework')
-rw-r--r--framework/Web/UI/ActiveControls/TActivePageAdapter.php18
-rw-r--r--framework/Web/UI/ActiveControls/TActivePanel.php16
-rw-r--r--framework/Web/UI/ActiveControls/TCallbackClientScript.php8
3 files changed, 36 insertions, 6 deletions
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
index 3b386902..2df19053 100644
--- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
@@ -58,6 +58,8 @@ class TActivePageAdapter extends TControlAdapter
*/
private $_callbackClient;
+ private $_controlsToRender=array();
+
/**
* Constructor, trap errors and exception to let the callback response
* handle them.
@@ -84,6 +86,18 @@ class TActivePageAdapter extends TControlAdapter
}
/**
+ * Register a control for defered render() call.
+ * @param TControl control for defered rendering
+ * @param THtmlWriter the renderer
+ */
+ public function registerControlToRender($control,$writer)
+ {
+ $id = $control->getUniqueID();
+ if(!isset($this->_controlsToRender[$id]))
+ $this->_controlsToRender[$id] = array($control,$writer);
+ }
+
+ /**
* Trap errors and exceptions to be handled by TCallbackErrorHandler.
*/
protected function trapCallbackErrorsExceptions()
@@ -108,6 +122,10 @@ class TActivePageAdapter extends TControlAdapter
*/
protected function renderResponse($writer)
{
+ //renders all the defered render() calls.
+ foreach($this->_controlsToRender as $rid => $forRender)
+ $forRender[0]->render($forRender[1]);
+
$response = $this->getResponse();
//send response data in header
diff --git a/framework/Web/UI/ActiveControls/TActivePanel.php b/framework/Web/UI/ActiveControls/TActivePanel.php
index 44f570b3..6f5c87dd 100644
--- a/framework/Web/UI/ActiveControls/TActivePanel.php
+++ b/framework/Web/UI/ActiveControls/TActivePanel.php
@@ -59,13 +59,23 @@ class TActivePanel extends TPanel implements IActiveControl
/**
* Renders and replaces the panel's content on the client-side.
+ * When render() is called before the OnPreRender event, such as when render()
+ * is called during a callback event handler, the rendering
+ * is defered until OnPreRender event is raised.
* @param THtmlWriter html writer
*/
public function render($writer)
{
- parent::render($writer);
- if($this->getActiveControl()->canUpdateClientSide())
- $this->getPage()->getCallbackClient()->replaceContent($this,$writer);
+ if($this->getHasPreRendered())
+ {
+ parent::render($writer);
+ if($this->getActiveControl()->canUpdateClientSide())
+ $this->getPage()->getCallbackClient()->replaceContent($this,$writer);
+ }
+ else
+ {
+ $this->getPage()->getAdapter()->registerControlToRender($this,$writer);
+ }
}
}
diff --git a/framework/Web/UI/ActiveControls/TCallbackClientScript.php b/framework/Web/UI/ActiveControls/TCallbackClientScript.php
index 11f3d1ff..ebc5942f 100644
--- a/framework/Web/UI/ActiveControls/TCallbackClientScript.php
+++ b/framework/Web/UI/ActiveControls/TCallbackClientScript.php
@@ -152,7 +152,7 @@ class TCallbackClientScript extends TApplicationComponent
*/
public function raiseClientEvent($control, $eventName)
{
- $this->callClientFunction('Event.fireEvent',
+ $this->callClientFunction('Event.fireEvent',
array($control, strtolower($eventName)));
}
@@ -382,14 +382,16 @@ class TCallbackClientScript extends TApplicationComponent
/**
* Renders the control and return the content boundary from
* TCallbackResponseWriter. This method should only be used by framework
- * component developers.
+ * component developers. The render() method is defered to be called in the
+ * TActivePageAdapter class.
* @param TControl control to be rendered on callback response.
* @return string the boundary for which the rendered content is wrapped.
*/
private function getRenderedContentBoundary($control)
{
$writer = $this->getResponse()->createHtmlWriter();
- $control->render($writer);
+ $adapter = $control->getPage()->getAdapter();
+ $adapter->registerControlToRender($control, $writer);
return $writer->getWriter()->getBoundary();
}