From b196ea0e2e9ab9078022e88326edecf1ba5b2f9f Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 15 Sep 2006 23:49:56 +0000 Subject: Defer render() calls in callback event handler to a later stage. --- .gitattributes | 8 ++++ .../Web/UI/ActiveControls/TActivePageAdapter.php | 18 ++++++++ framework/Web/UI/ActiveControls/TActivePanel.php | 16 +++++-- .../UI/ActiveControls/TCallbackClientScript.php | 8 ++-- .../pages/ActiveControlExpressionTag.page | 27 ++++++++++++ .../protected/pages/ActiveControlExpressionTag.php | 26 ++++++++++++ .../protected/pages/ActiveListBoxMasterTest.page | 28 +++++++++++++ .../protected/pages/ActiveListBoxMasterTest.php | 47 +++++++++++++++++++++ .../protected/pages/TActiveCheckBoxListTest.page | 14 +++---- .../protected/pages/TestMasterPage.php | 7 ++++ .../protected/pages/TestMasterPage.tpl | 12 ++++++ .../tests/ActiveControlExpressTagTestCase.php | 20 +++++++++ .../tests/ActiveListBoxMasterTestCase.php | 49 ++++++++++++++++++++++ 13 files changed, 267 insertions(+), 13 deletions(-) create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.tpl create mode 100644 tests/FunctionalTests/active-controls/tests/ActiveControlExpressTagTestCase.php create mode 100644 tests/FunctionalTests/active-controls/tests/ActiveListBoxMasterTestCase.php diff --git a/.gitattributes b/.gitattributes index b2349fd8..c9758170 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1888,10 +1888,14 @@ requirements/messages.txt -text requirements/template-bg.html -text requirements/template-zh.html -text requirements/template.html -text +tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveImageButtonTest.page -text tests/FunctionalTests/active-controls/protected/pages/ActiveImageButtonTest.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveLinkButtonTest.page -text tests/FunctionalTests/active-controls/protected/pages/ActiveLinkButtonTest.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxTest.page -text tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxTest.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveRadioButtonListTest.page -text @@ -1910,14 +1914,18 @@ tests/FunctionalTests/active-controls/protected/pages/ReplaceContentTest.page -t tests/FunctionalTests/active-controls/protected/pages/ReplaceContentTest.php -text tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.page -text tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.php -text +tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.php -text +tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.tpl -text tests/FunctionalTests/active-controls/protected/pages/TextBoxValidationCallback.page -text tests/FunctionalTests/active-controls/protected/pages/TextBoxValidationCallback.php -text tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.page -text tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.php -text tests/FunctionalTests/active-controls/protected/pages/group.gif -text tests/FunctionalTests/active-controls/protected/pages/report.gif -text +tests/FunctionalTests/active-controls/tests/ActiveControlExpressTagTestCase.php -text tests/FunctionalTests/active-controls/tests/ActiveImageButtonTestCase.php -text tests/FunctionalTests/active-controls/tests/ActiveLinkButtonTestCase.php -text +tests/FunctionalTests/active-controls/tests/ActiveListBoxMasterTestCase.php -text tests/FunctionalTests/active-controls/tests/ActiveListBoxTestCase.php -text tests/FunctionalTests/active-controls/tests/ActiveRadioButtonListTestCase.php -text tests/FunctionalTests/active-controls/tests/ActiveRadioButtonTestCase.php -text 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. @@ -83,6 +85,18 @@ class TActivePageAdapter extends TControlAdapter $this->raiseCallbackEvent(); } + /** + * 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. */ @@ -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(); } diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.page new file mode 100644 index 00000000..7b983cd7 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.page @@ -0,0 +1,27 @@ + + +

Active Control With Expression Tag Test

+ + + + + +
+result - <%# $this->DataItem %> +
+Text box content: <%= $this->textbox1->SafeText %> +
+
+ + + More Contents: <%= $this->textbox1->SafeText %> + + + + + + + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.php new file mode 100644 index 00000000..e873ae9d --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.php @@ -0,0 +1,26 @@ +subpanel1->Visible = true; + $data = array('1', 'two'); + $this->repeater1->DataSource = $data; + $this->repeater1->dataBind(); + } + + public function button1_callback($sender, $param) + { + $this->panel1->renderControl($param->NewWriter); + $this->button2->Enabled=true; + } + + public function button2_callback($sender, $param) + { + $this->panel2->Visible=true; + $this->Page->CallbackClient->insertContentAfter('contents', $this->panel2); + } +} + +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.page new file mode 100644 index 00000000..f7c6baaf --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.page @@ -0,0 +1,28 @@ +<%@ MasterClass="Application.pages.TestMasterPage" %> + + +

Active List Box Functional Test

+ + + + + + + + + +
+ +
+
+ + + + + + + +
+ + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.php new file mode 100644 index 00000000..d2991653 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveListBoxMasterTest.php @@ -0,0 +1,47 @@ +getSelectedValues(); + $this->label1->setText("Selection: ".implode(', ', $values)); + } + + function select_index_123() + { + $this->list1->setSelectedIndices(array(1,2,3)); + } + + function select_index_4() + { + $this->list1->setSelectedIndex(4); + } + + function clear_selections() + { + $this->list1->clearSelection(); + } + + function select_value_1() + { + $this->list1->setSelectedValue("value 1"); + } + + function select_values_25() + { + $this->list1->setSelectedValues(array('value 2', 'value 5')); + } + + function change_to_multiple() + { + $this->list1->SelectionMode="Multiple"; + } + + function change_to_single() + { + $this->list1->SelectionMode="Single"; + } +} + +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/TActiveCheckBoxListTest.page b/tests/FunctionalTests/active-controls/protected/pages/TActiveCheckBoxListTest.page index b30ced69..f3332bad 100644 --- a/tests/FunctionalTests/active-controls/protected/pages/TActiveCheckBoxListTest.page +++ b/tests/FunctionalTests/active-controls/protected/pages/TActiveCheckBoxListTest.page @@ -1,12 +1,12 @@

TActiveCheckBoxList Test Case

- + - - - - + + + +
@@ -18,7 +18,7 @@
- + - +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.php b/tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.php new file mode 100644 index 00000000..dc643e52 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.tpl b/tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.tpl new file mode 100644 index 00000000..a599ded4 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/TestMasterPage.tpl @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/tests/FunctionalTests/active-controls/tests/ActiveControlExpressTagTestCase.php b/tests/FunctionalTests/active-controls/tests/ActiveControlExpressTagTestCase.php new file mode 100644 index 00000000..7da7315c --- /dev/null +++ b/tests/FunctionalTests/active-controls/tests/ActiveControlExpressTagTestCase.php @@ -0,0 +1,20 @@ +open('active-controls/index.php?page=ActiveControlExpressionTag'); + $this->assertTextPresent('Active Control With Expression Tag Test'); + $this->assertTextNotPresent('Text box content:'); + + $this->type('textbox1', 'Hello world'); + $this->click('button1'); + $this->pause(800); + + $this->assertText('repeats', 'result - 1 result - two'); + $this->assertText('contents', 'Text box content: Hello world'); + } +} + +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/tests/ActiveListBoxMasterTestCase.php b/tests/FunctionalTests/active-controls/tests/ActiveListBoxMasterTestCase.php new file mode 100644 index 00000000..7f006d9e --- /dev/null +++ b/tests/FunctionalTests/active-controls/tests/ActiveListBoxMasterTestCase.php @@ -0,0 +1,49 @@ +open("active-controls/index.php?page=ActiveListBoxMasterTest"); + $this->assertTextPresent('Active List Box Functional Test'); + + $base = 'ctl0_body_'; + + $this->assertText($base."label1", "Label 1"); + + $this->click($base."button1"); + $this->pause(800); + $this->assertSelectedIndexes($base.'list1', '1,2,3'); + + $this->click($base.'button3'); + $this->pause(800); + $this->assertSelectedIndexes($base.'list1', '0'); + + $this->click($base.'button4'); + $this->pause(800); + $this->assertSelectedIndexes($base.'list1', '4'); + + $this->click($base.'button5'); + $this->pause(800); + $this->assertSelectedIndexes($base.'list1', '1,4'); + + $this->click($base.'button2'); + $this->pause(800); + $this->assertEmptySelection($base."list1"); + + $this->click($base.'button6'); + $this->pause(800); + $this->click($base."button1"); + $this->pause(800); + $this->assertSelectedIndexes($base.'list1', '1,2,3'); + + $this->select($base."list1", "item 1"); + $this->pause(800); + $this->assertText($base.'label1', 'Selection: value 1'); + + $this->addSelection($base."list1", "item 4"); + $this->pause(800); + $this->assertText($base.'label1', 'Selection: value 1, value 4'); + } +} +?> \ No newline at end of file -- cgit v1.2.3