| [ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TPage class file 4 * 5 * @author Qiang Xue <qiang.xue@gmail.com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TPage.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI 11 */ 12 13 Prado::using('System.Web.UI.WebControls.*'); 14 Prado::using('System.Web.UI.TControl'); 15 Prado::using('System.Web.UI.WebControls.TWebControl'); 16 Prado::using('System.Web.UI.TCompositeControl'); 17 Prado::using('System.Web.UI.TTemplateControl'); 18 Prado::using('System.Web.UI.TForm'); 19 Prado::using('System.Web.UI.TClientScriptManager'); 20 21 /** 22 * TPage class 23 * 24 * @author Qiang Xue <qiang.xue@gmail.com> 25 * @version $Id: TPage.php 1397 2006-09-07 07:55:53Z wei $ 26 * @package System.Web.UI 27 * @since 3.0 28 */ 29 class TPage extends TTemplateControl 30 { 31 /** 32 * system post fields 33 */ 34 const FIELD_POSTBACK_TARGET='PRADO_POSTBACK_TARGET'; 35 const FIELD_POSTBACK_PARAMETER='PRADO_POSTBACK_PARAMETER'; 36 const FIELD_LASTFOCUS='PRADO_LASTFOCUS'; 37 const FIELD_PAGESTATE='PRADO_PAGESTATE'; 38 const FIELD_CALLBACK_TARGET='PRADO_CALLBACK_TARGET'; 39 const FIELD_CALLBACK_PARAMETER='PRADO_CALLBACK_PARAMETER'; 40 const FIELD_CALLBACK_ID='PRADO_CALLBACK_ID'; 41 /** 42 * @var array system post fields 43 */ 44 private static $_systemPostFields=array( 45 'PRADO_POSTBACK_TARGET'=>true, 46 'PRADO_POSTBACK_PARAMETER'=>true, 47 'PRADO_LASTFOCUS'=>true, 48 'PRADO_PAGESTATE'=>true, 49 'PRADO_CALLBACK_TARGET'=>true, 50 'PRADO_CALLBACK_PARAMETER'=>true, 51 'PRADO_CALLBACK_ID'=>true 52 ); 53 /** 54 * @var TForm form instance 55 */ 56 private $_form=null; 57 /** 58 * @var THead head instance 59 */ 60 private $_head=null; 61 /** 62 * @var array list of registered validators 63 */ 64 private $_validators=array(); 65 /** 66 * @var boolean if validation has been performed 67 */ 68 private $_validated=false; 69 /** 70 * @var TTheme page theme 71 */ 72 private $_theme=null; 73 /** 74 * @var string page title set when Head is not in page yet 75 */ 76 private $_title=null; 77 /** 78 * @var TTheme page stylesheet theme 79 */ 80 private $_styleSheet=null; 81 /** 82 * @var TClientScriptManager client script manager 83 */ 84 private $_clientScript=null; 85 /** 86 * @var TMap data post back by user 87 */ 88 private $_postData; 89 /** 90 * @var TMap postback data that is not handled during first invocation of LoadPostData. 91 */ 92 private $_restPostData; 93 /** 94 * @var array list of controls whose data have been changed due to the postback 95 */ 96 private $_controlsPostDataChanged=array(); 97 /** 98 * @var array list of controls that need to load post data in the current request 99 */ 100 private $_controlsRequiringPostData=array(); 101 /** 102 * @var array list of controls that need to load post data in the next postback 103 */ 104 private $_controlsRegisteredForPostData=array(); 105 /** 106 * @var TControl control that needs to raise postback event 107 */ 108 private $_postBackEventTarget=null; 109 /** 110 * @var string postback event parameter 111 */ 112 private $_postBackEventParameter=null; 113 /** 114 * @var boolean whether the form has been rendered 115 */ 116 private $_formRendered=false; 117 /** 118 * @var boolean whether the current rendering is within a form 119 */ 120 private $_inFormRender=false; 121 /** 122 * @var TControl|string the control or the ID of the element on the page to be focused when the page is sent back to user 123 */ 124 private $_focus=null; 125 /** 126 * @var string page path to this page 127 */ 128 private $_pagePath=''; 129 /** 130 * @var boolean whether page state should be HMAC validated 131 */ 132 private $_enableStateValidation=true; 133 /** 134 * @var boolean whether page state should be encrypted 135 */ 136 private $_enableStateEncryption=false; 137 /** 138 * @var string page state persister class name 139 */ 140 private $_statePersisterClass='System.Web.UI.TPageStatePersister'; 141 /** 142 * @var mixed page state persister 143 */ 144 private $_statePersister=null; 145 146 /** 147 * Constructor. 148 * Sets the page object to itself. 149 * Derived classes must call parent implementation. 150 */ 151 public function __construct() 152 { 153 parent::__construct(); 154 $this->setPage($this); 155 } 156 157 /** 158 * Runs through the page lifecycles. 159 * @param THtmlTextWriter the HTML writer 160 */ 161 public function run($writer) 162 { 163 Prado::trace("Running page life cycles",'System.Web.UI.TPage'); 164 $this->determinePostBackMode(); 165 166 if($this->getIsPostBack()) 167 { 168 if($this->getIsCallback()) 169 $this->processCallbackRequest($writer); 170 else 171 $this->processPostBackRequest($writer); 172 } 173 else 174 $this->processNormalRequest($writer); 175 } 176 177 protected function processNormalRequest($writer) 178 { 179 Prado::trace("Page onPreInit()",'System.Web.UI.TPage'); 180 $this->onPreInit(null); 181 182 Prado::trace("Page initRecursive()",'System.Web.UI.TPage'); 183 $this->initRecursive(); 184 185 Prado::trace("Page onInitComplete()",'System.Web.UI.TPage'); 186 $this->onInitComplete(null); 187 188 Prado::trace("Page onPreLoad()",'System.Web.UI.TPage'); 189 $this->onPreLoad(null); 190 Prado::trace("Page loadRecursive()",'System.Web.UI.TPage'); 191 $this->loadRecursive(); 192 Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage'); 193 $this->onLoadComplete(null); 194 195 Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage'); 196 $this->preRenderRecursive(); 197 Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage'); 198 $this->onPreRenderComplete(null); 199 200 Prado::trace("Page savePageState()",'System.Web.UI.TPage'); 201 $this->savePageState(); 202 Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage'); 203 $this->onSaveStateComplete(null); 204 205 Prado::trace("Page renderControl()",'System.Web.UI.TPage'); 206 $this->renderControl($writer); 207 Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage'); 208 $this->unloadRecursive(); 209 } 210 211 protected function processPostBackRequest($writer) 212 { 213 Prado::trace("Page onPreInit()",'System.Web.UI.TPage'); 214 $this->onPreInit(null); 215 216 Prado::trace("Page initRecursive()",'System.Web.UI.TPage'); 217 $this->initRecursive(); 218 219 Prado::trace("Page onInitComplete()",'System.Web.UI.TPage'); 220 $this->onInitComplete(null); 221 222 $this->_restPostData=new TMap; 223 Prado::trace("Page loadPageState()",'System.Web.UI.TPage'); 224 $this->loadPageState(); 225 Prado::trace("Page processPostData()",'System.Web.UI.TPage'); 226 $this->processPostData($this->_postData,true); 227 Prado::trace("Page onPreLoad()",'System.Web.UI.TPage'); 228 $this->onPreLoad(null); 229 Prado::trace("Page loadRecursive()",'System.Web.UI.TPage'); 230 $this->loadRecursive(); 231 Prado::trace("Page processPostData()",'System.Web.UI.TPage'); 232 $this->processPostData($this->_restPostData,false); 233 Prado::trace("Page raiseChangedEvents()",'System.Web.UI.TPage'); 234 $this->raiseChangedEvents(); 235 Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage'); 236 $this->raisePostBackEvent(); 237 Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage'); 238 $this->onLoadComplete(null); 239 240 Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage'); 241 $this->preRenderRecursive(); 242 Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage'); 243 $this->onPreRenderComplete(null); 244 245 Prado::trace("Page savePageState()",'System.Web.UI.TPage'); 246 $this->savePageState(); 247 Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage'); 248 $this->onSaveStateComplete(null); 249 250 Prado::trace("Page renderControl()",'System.Web.UI.TPage'); 251 $this->renderControl($writer); 252 Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage'); 253 $this->unloadRecursive(); 254 } 255 256 protected function processCallbackRequest($writer) 257 { 258 } 259 260 /** 261 * @return TForm the form on the page 262 */ 263 public function getForm() 264 { 265 return $this->_form; 266 } 267 268 /** 269 * Registers a TForm instance to the page. 270 * Note, a page can contain at most one TForm instance. 271 * @param TForm the form on the page 272 * @throws TInvalidOperationException if this method is invoked twice or more. 273 */ 274 public function setForm(TForm $form) 275 { 276 if($this->_form===null) 277 $this->_form=$form; 278 else 279 throw new TInvalidOperationException('page_form_duplicated'); 280 } 281 282 /** 283 * Returns a list of registered validators. 284 * If validation group is specified, only the validators in that group will be returned. 285 * @param string validation group 286 * @return TList registered validators in the requested group. If the group is null, all validators will be returned. 287 */ 288 public function getValidators($validationGroup=null) 289 { 290 if(!$this->_validators) 291 $this->_validators=new TList; 292 if($validationGroup===null) 293 return $this->_validators; 294 else 295 { 296 $list=new TList; 297 foreach($this->_validators as $validator) 298 if($validator->getValidationGroup()===$validationGroup) 299 $list->add($validator); 300 return $list; 301 } 302 } 303 304 /** 305 * Performs input validation. 306 * This method will invoke the registered validators to perform the actual validation. 307 * If validation group is specified, only the validators in that group will be invoked. 308 * @param string validation group. If null, all validators will perform validation. 309 */ 310 public function validate($validationGroup=null) 311 { 312 Prado::trace("Page validate()",'System.Web.UI.TPage'); 313 $this->_validated=true; 314 if($this->_validators && $this->_validators->getCount()) 315 { 316 if($validationGroup===null) 317 { 318 foreach($this->_validators as $validator) 319 $validator->validate(); 320 } 321 else 322 { 323 foreach($this->_validators as $validator) 324 { 325 if($validator->getValidationGroup()===$validationGroup) 326 $validator->validate(); 327 } 328 } 329 } 330 } 331 332 /** 333 * Returns whether user input is valid or not. 334 * This method must be invoked after {@link validate} is called. 335 * @return boolean whether the user input is valid or not. 336 * @throws TInvalidOperationException if {@link validate} is not invoked yet. 337 */ 338 public function getIsValid() 339 { 340 if($this->_validated) 341 { 342 if($this->_validators && $this->_validators->getCount()) 343 { 344 foreach($this->_validators as $validator) 345 if(!$validator->getIsValid()) 346 return false; 347 } 348 return true; 349 } 350 else 351 throw new TInvalidOperationException('page_isvalid_unknown'); 352 } 353 354 /** 355 * @return TTheme the theme used for the page. Defaults to null. 356 */ 357 public function getTheme() 358 { 359 if(is_string($this->_theme)) 360 $this->_theme=$this->getService()->getThemeManager()->getTheme($this->_theme); 361 return $this->_theme; 362 } 363 364 /** 365 * Sets the theme to be used for the page. 366 * @param string|TTheme the theme name or the theme object to be used for the page. 367 */ 368 public function setTheme($value) 369 { 370 $this->_theme=$value; 371 } 372 373 374 /** 375 * @return TTheme the stylesheet theme used for the page. Defaults to null. 376 */ 377 public function getStyleSheetTheme() 378 { 379 if(is_string($this->_styleSheet)) 380 $this->_styleSheet=$this->getService()->getThemeManager()->getTheme($this->_styleSheet); 381 return $this->_styleSheet; 382 } 383 384 /** 385 * Sets the stylesheet theme to be used for the page. 386 * @param string|TTheme the stylesheet theme name or the stylesheet theme object to be used for the page. 387 */ 388 public function setStyleSheetTheme($value) 389 { 390 $this->_styleSheet=$value; 391 } 392 393 /** 394 * Applies a skin in the current theme to a control. 395 * This method should only be used by framework developers. 396 * @param TControl a control to be applied skin with 397 */ 398 public function applyControlSkin($control) 399 { 400 if(($theme=$this->getTheme())!==null) 401 $theme->applySkin($control); 402 } 403 404 /** 405 * Applies a stylesheet skin in the current theme to a control. 406 * This method should only be used by framework developers. 407 * @param TControl a control to be applied stylesheet skin with 408 */ 409 public function applyControlStyleSheet($control) 410 { 411 if(($theme=$this->getStyleSheetTheme())!==null) 412 $theme->applySkin($control); 413 } 414 415 /** 416 * @return TClientScriptManager client script manager 417 */ 418 public function getClientScript() 419 { 420 if(!$this->_clientScript) 421 $this->_clientScript=new TClientScriptManager($this); 422 return $this->_clientScript; 423 } 424 425 /** 426 * Raises OnPreInit event. 427 * This method is invoked right before {@link onInit OnInit} stage. 428 * You may override this method to provide additional initialization that 429 * should be done before {@link onInit OnInit} (e.g. setting {@link setTheme Theme} or 430 * {@link setStyleSheetTheme StyleSheetTheme}). 431 * Remember to call the parent implementation to ensure OnPreInit event is raised. 432 * @param mixed event parameter 433 */ 434 public function onPreInit($param) 435 { 436 $this->raiseEvent('OnPreInit',$this,$param); 437 } 438 439 /** 440 * Raises OnInitComplete event. 441 * This method is invoked right after {@link onInit OnInit} stage and before {@link onLoad OnLoad} stage. 442 * You may override this method to provide additional initialization that 443 * should be done after {@link onInit OnInit}. 444 * Remember to call the parent implementation to ensure OnInitComplete event is raised. 445 * @param mixed event parameter 446 */ 447 public function onInitComplete($param) 448 { 449 $this->raiseEvent('OnInitComplete',$this,$param); 450 } 451 452 /** 453 * Raises OnPreLoad event. 454 * This method is invoked right before {@link onLoad OnLoad} stage. 455 * You may override this method to provide additional page loading logic that 456 * should be done before {@link onLoad OnLoad}. 457 * Remember to call the parent implementation to ensure OnPreLoad event is raised. 458 * @param mixed event parameter 459 */ 460 public function onPreLoad($param) 461 { 462 $this->raiseEvent('OnPreLoad',$this,$param); 463 } 464 465 /** 466 * Raises OnLoadComplete event. 467 * This method is invoked right after {@link onLoad OnLoad} stage. 468 * You may override this method to provide additional page loading logic that 469 * should be done after {@link onLoad OnLoad}. 470 * Remember to call the parent implementation to ensure OnLoadComplete event is raised. 471 * @param mixed event parameter 472 */ 473 public function onLoadComplete($param) 474 { 475 $this->raiseEvent('OnLoadComplete',$this,$param); 476 } 477 478 /** 479 * Raises OnPreRenderComplete event. 480 * This method is invoked right after {@link onPreRender OnPreRender} stage. 481 * You may override this method to provide additional preparation for page rendering 482 * that should be done after {@link onPreRender OnPreRender}. 483 * Remember to call the parent implementation to ensure OnPreRenderComplete event is raised. 484 * @param mixed event parameter 485 */ 486 public function onPreRenderComplete($param) 487 { 488 $this->raiseEvent('OnPreRenderComplete',$this,$param); 489 $cs=$this->getClientScript(); 490 if($this->_theme instanceof ITheme) 491 { 492 foreach($this->_theme->getStyleSheetFiles() as $url) 493 $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url)); 494 foreach($this->_theme->getJavaScriptFiles() as $url) 495 $cs->registerHeadScriptFile($url,$url); 496 } 497 if($this->_styleSheet instanceof ITheme) 498 { 499 foreach($this->_styleSheet->getStyleSheetFiles() as $url) 500 $cs->registerStyleSheetFile($url,$url,$this->getCssMediaType($url)); 501 foreach($this->_styleSheet->getJavaScriptFiles() as $url) 502 $cs->registerHeadScriptFile($url,$url); 503 } 504 } 505 506 /** 507 * Determines the media type of the CSS file. 508 * The media type is determined according to the following file name pattern: 509 * xxx.media-type.extension 510 * For example, 'mystyle.print.css' means its media type is 'print'. 511 * @param string CSS URL 512 * @return string media type of the CSS file 513 */ 514 private function getCssMediaType($url) 515 { 516 $segs=explode('.',basename($url)); 517 if(isset($segs[2])) 518 return $segs[count($segs)-2]; 519 else 520 return ''; 521 } 522 523 /** 524 * Raises OnSaveStateComplete event. 525 * This method is invoked right after {@link onSaveState OnSaveState} stage. 526 * You may override this method to provide additional logic after page state is saved. 527 * Remember to call the parent implementation to ensure OnSaveStateComplete event is raised. 528 * @param mixed event parameter 529 */ 530 public function onSaveStateComplete($param) 531 { 532 $this->raiseEvent('OnSaveStateComplete',$this,$param); 533 } 534 535 /** 536 * Determines whether the current page request is a postback. 537 * Call {@link getIsPostBack} to get the result. 538 */ 539 private function determinePostBackMode() 540 { 541 $postData=$this->getRequest(); 542 if($postData->contains(self::FIELD_PAGESTATE) || $postData->contains(self::FIELD_POSTBACK_TARGET)) 543 $this->_postData=$postData; 544 } 545 546 /** 547 * @return boolean whether the current page request is a postback 548 */ 549 public function getIsPostBack() 550 { 551 return $this->_postData!==null; 552 } 553 554 /** 555 * TBD 556 * @return boolean whether this is a callback request 557 */ 558 public function getIsCallback() 559 { 560 return false; 561 } 562 563 /** 564 * This method is invoked when control state is to be saved. 565 * You can override this method to do last step state saving. 566 * Parent implementation must be invoked. 567 */ 568 public function saveState() 569 { 570 parent::saveState(); 571 $this->setViewState('ControlsRequiringPostBack',$this->_controlsRegisteredForPostData,array()); 572 } 573 574 /** 575 * This method is invoked right after the control has loaded its state. 576 * You can override this method to initialize data from the control state. 577 * Parent implementation must be invoked. 578 */ 579 public function loadState() 580 { 581 parent::loadState(); 582 $this->_controlsRequiringPostData=$this->getViewState('ControlsRequiringPostBack',array()); 583 } 584 585 /** 586 * Loads page state from persistent storage. 587 */ 588 protected function loadPageState() 589 { 590 Prado::trace("Loading state",'System.Web.UI.TPage'); 591 $state=$this->getStatePersister()->load(); 592 $this->loadStateRecursive($state,$this->getEnableViewState()); 593 } 594 595 /** 596 * Saves page state from persistent storage. 597 */ 598 protected function savePageState() 599 { 600 Prado::trace("Saving state",'System.Web.UI.TPage'); 601 $state=&$this->saveStateRecursive($this->getEnableViewState()); 602 $this->getStatePersister()->save($state); 603 } 604 605 /** 606 * @param string the field name 607 * @return boolean whether the specified field is a system field in postback data 608 */ 609 protected function isSystemPostField($field) 610 { 611 return isset(self::$_systemPostFields[$field]); 612 } 613 614 /** 615 * Registers a control for loading post data in the next postback. 616 * This method needs to be invoked if the control to load post data 617 * may not have a post variable in some cases. For example, a checkbox, 618 * if not checked, will not have a post value. 619 * @param TControl control registered for loading post data 620 */ 621 public function registerRequiresPostData(TControl $control) 622 { 623 $this->_controlsRegisteredForPostData[$control->getUniqueID()]=true; 624 } 625 626 /** 627 * @return TControl the control responsible for the current postback event, null if nonexistent 628 */ 629 public function getPostBackEventTarget() 630 { 631 if($this->_postBackEventTarget===null) 632 { 633 $eventTarget=$this->_postData->itemAt(self::FIELD_POSTBACK_TARGET); 634 if(!empty($eventTarget)) 635 $this->_postBackEventTarget=$this->findControl($eventTarget); 636 } 637 return $this->_postBackEventTarget; 638 } 639 640 /** 641 * Registers a control to raise postback event in the current request. 642 * @param TControl control registered to raise postback event. 643 */ 644 public function setPostBackEventTarget(TControl $control) 645 { 646 $this->_postBackEventTarget=$control; 647 } 648 649 /** 650 * @return string postback event parameter 651 */ 652 public function getPostBackEventParameter() 653 { 654 if($this->_postBackEventParameter===null) 655 { 656 if(($this->_postBackEventParameter=$this->_postData->itemAt(self::FIELD_POSTBACK_PARAMETER))===null) 657 $this->_postBackEventParameter=''; 658 } 659 return $this->_postBackEventParameter; 660 } 661 662 /** 663 * @param string postback event parameter 664 */ 665 public function setPostBackEventParameter($value) 666 { 667 $this->_postBackEventParameter=$value; 668 } 669 670 /** 671 * Processes post data. 672 * @param TMap post data to be processed 673 * @param boolean whether this method is invoked before {@link onLoad OnLoad}. 674 */ 675 protected function processPostData($postData,$beforeLoad) 676 { 677 if($beforeLoad) 678 $this->_restPostData=new TMap; 679 foreach($postData as $key=>$value) 680 { 681 if($this->isSystemPostField($key)) 682 continue; 683 else if($control=$this->findControl($key)) 684 { 685 if($control instanceof IPostBackDataHandler) 686 { 687 if($control->loadPostData($key,$postData)) 688 $this->_controlsPostDataChanged[]=$control; 689 } 690 else if($control instanceof IPostBackEventHandler && 691 empty($this->_postData[self::FIELD_POSTBACK_TARGET])) 692 { 693 $this->_postData->add(self::FIELD_POSTBACK_TARGET,$key); // not calling setPostBackEventTarget() because the control may be removed later 694 } 695 unset($this->_controlsRequiringPostData[$key]); 696 } 697 else if($beforeLoad) 698 $this->_restPostData->add($key,$value); 699 } 700 701 foreach($this->_controlsRequiringPostData as $key=>$value) 702 { 703 if($control=$this->findControl($key)) 704 { 705 if($control instanceof IPostBackDataHandler) 706 { 707 if($control->loadPostData($key,$this->_postData)) 708 $this->_controlsPostDataChanged[]=$control; 709 } 710 else 711 throw new TInvalidDataValueException('page_postbackcontrol_invalid',$key); 712 unset($this->_controlsRequiringPostData[$key]); 713 } 714 } 715 } 716 717 /** 718 * Raises OnPostDataChangedEvent for controls whose data have been changed due to the postback. 719 */ 720 private function raiseChangedEvents() 721 { 722 foreach($this->_controlsPostDataChanged as $control) 723 $control->raisePostDataChangedEvent(); 724 } 725 726 /** 727 * Raises PostBack event. 728 */ 729 private function raisePostBackEvent() 730 { 731 if(($postBackHandler=$this->getPostBackEventTarget())===null) 732 $this->validate(); 733 else if($postBackHandler instanceof IPostBackEventHandler) 734 $postBackHandler->raisePostBackEvent($this->getPostBackEventParameter()); 735 } 736 737 /** 738 * Ensures the control is rendered within a form. 739 * @param TControl the control to be rendered 740 * @throws TConfigurationException if the control is outside of the form 741 */ 742 public function ensureRenderInForm($control) 743 { 744 if(!$this->_inFormRender) 745 throw new TConfigurationException('page_control_outofform',$control->getUniqueID()); 746 } 747 748 /** 749 * @internal This method is invoked by TForm at the beginning of its rendering 750 */ 751 public function beginFormRender($writer) 752 { 753 if($this->_formRendered) 754 throw new TConfigurationException('page_form_duplicated'); 755 $this->_formRendered=true; 756 $this->_inFormRender=true; 757 $cs=$this->getClientScript(); 758 $cs->renderHiddenFields($writer); 759 $cs->renderScriptFiles($writer); 760 $cs->renderBeginScripts($writer); 761 } 762 763 /** 764 * @internal This method is invoked by TForm at the end of its rendering 765 */ 766 public function endFormRender($writer) 767 { 768 $cs=$this->getClientScript(); 769 if($this->getClientSupportsJavaScript()) 770 { 771 if($this->_focus) 772 { 773 if(($this->_focus instanceof TControl) && $this->_focus->getVisible(true) || is_string($this->_focus)) 774 $cs->registerFocusControl($this->_focus); 775 } 776 else if($this->_postData && ($lastFocus=$this->_postData->itemAt(self::FIELD_LASTFOCUS))!==null) 777 $cs->registerFocusControl($lastFocus); 778 $cs->renderHiddenFields($writer); 779 $cs->renderScriptFiles($writer); 780 $cs->renderEndScripts($writer); 781 } 782 else 783 $cs->renderHiddenFields($writer); 784 $this->_inFormRender=false; 785 } 786 787 /** 788 * Sets input focus on a control after the page is rendered to users. 789 * @param TControl|string control to receive focus, or the ID of the element on the page to receive focus 790 */ 791 public function setFocus($value) 792 { 793 $this->_focus=$value; 794 } 795 796 /** 797 * @return boolean whether client supports javascript. Currently, this 798 * method always returns true. If future, we may add some browser capability 799 * detection functionality. 800 */ 801 public function getClientSupportsJavaScript() 802 { 803 // todo 804 return true; 805 } 806 807 /** 808 * @return THead page head, null if not available 809 */ 810 public function getHead() 811 { 812 return $this->_head; 813 } 814 815 /** 816 * @param THead page head 817 * @throws TInvalidOperationException if a head already exists 818 */ 819 public function setHead(THead $value) 820 { 821 if($this->_head) 822 throw new TInvalidOperationException('page_head_duplicated'); 823 $this->_head=$value; 824 if($this->_title!==null) 825 { 826 $this->_head->setTitle($this->_title); 827 $this->_title=null; 828 } 829 } 830 831 /** 832 * @return string page title. 833 */ 834 public function getTitle() 835 { 836 if($this->_head) 837 return $this->_head->getTitle(); 838 else 839 return $this->_title===null ? '' : $this->_title; 840 } 841 842 /** 843 * Sets the page title. 844 * Note, a {@link THead} control needs to place on the page 845 * in order that this title be rendered. 846 * @param string page title. This will override the title set in {@link getHead Head}. 847 */ 848 public function setTitle($value) 849 { 850 if($this->_head) 851 $this->_head->setTitle($value); 852 else 853 $this->_title=$value; 854 } 855 856 /** 857 * @return string class name of the page state persister. Defaults to TPageStatePersister. 858 */ 859 public function getStatePersisterClass() 860 { 861 return $this->_statePersisterClass; 862 } 863 864 /** 865 * @param string class name of the page state persister. 866 */ 867 public function setStatePersisterClass($value) 868 { 869 $this->_statePersisterClass=$value; 870 } 871 872 /** 873 * @return IPageStatePersister page state persister 874 */ 875 public function getStatePersister() 876 { 877 if($this->_statePersister===null) 878 { 879 $this->_statePersister=Prado::createComponent($this->_statePersisterClass); 880 if(!($this->_statePersister instanceof IPageStatePersister)) 881 throw new TInvalidDataTypeException('page_statepersister_invalid'); 882 $this->_statePersister->setPage($this); 883 } 884 return $this->_statePersister; 885 } 886 887 /** 888 * @return boolean whether page state should be HMAC validated. Defaults to true. 889 */ 890 public function getEnableStateValidation() 891 { 892 return $this->_enableStateValidation; 893 } 894 895 /** 896 * @param boolean whether page state should be HMAC validated. 897 */ 898 public function setEnableStateValidation($value) 899 { 900 $this->_enableStateValidation=TPropertyValue::ensureBoolean($value); 901 } 902 903 /** 904 * @return boolean whether page state should be encrypted. Defaults to false. 905 */ 906 public function getEnableStateEncryption() 907 { 908 return $this->_enableStateEncryption; 909 } 910 911 /** 912 * @param boolean whether page state should be encrypted. 913 */ 914 public function setEnableStateEncryption($value) 915 { 916 $this->_enableStateEncryption=TPropertyValue::ensureBoolean($value); 917 } 918 919 /** 920 * @return string the requested page path for this page 921 */ 922 public function getPagePath() 923 { 924 return $this->_pagePath; 925 } 926 927 /** 928 * @param string the requested page path for this page 929 */ 930 public function setPagePath($value) 931 { 932 $this->_pagePath=$value; 933 } 934 } 935 936 /** 937 * IPageStatePersister interface. 938 * 939 * IPageStatePersister interface is required for all page state persister 940 * classes. 941 * 942 * @author Qiang Xue <qiang.xue@gmail.com> 943 * @version $Id: TPage.php 1397 2006-09-07 07:55:53Z wei $ 944 * @package System.Web.UI 945 * @since 3.0 946 */ 947 interface IPageStatePersister 948 { 949 /** 950 * @param TPage the page that this persister works for 951 */ 952 public function getPage(); 953 /** 954 * @param TPage the page that this persister works for 955 */ 956 public function setPage(TPage $page); 957 /** 958 * Saves state to persistent storage. 959 * @param mixed state to be stored 960 */ 961 public function save($state); 962 /** 963 * Loads page state from persistent storage 964 * @return mixed the restored state 965 */ 966 public function load(); 967 } 968 969 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |