From 54900d0145dfda07bde40dc6e1f0b31935b55444 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 17 Jan 2006 23:58:54 +0000 Subject: --- framework/Web/UI/WebControls/TBaseDataList.php | 40 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'framework/Web/UI/WebControls/TBaseDataList.php') diff --git a/framework/Web/UI/WebControls/TBaseDataList.php b/framework/Web/UI/WebControls/TBaseDataList.php index f5a09815..351fbbc9 100644 --- a/framework/Web/UI/WebControls/TBaseDataList.php +++ b/framework/Web/UI/WebControls/TBaseDataList.php @@ -42,11 +42,6 @@ Prado::using('System.Web.UI.WebControls.TDataBoundControl'); */ abstract class TBaseDataList extends TDataBoundControl { - /** - * @var TList list of key values - */ - private $_dataKeys=null; - /** * No body content should be added to data list control. * This method is invoked when body content is parsed and added to this control. @@ -200,9 +195,38 @@ abstract class TBaseDataList extends TDataBoundControl */ public function getDataKeys() { - if(!$this->_dataKeys) - $this->_dataKeys=new TList; - return $this->_dataKeys; + if(($dataKeys=$this->getViewState('DataKeys',null))===null) + { + $dataKeys=new TList; + $this->setViewState('DataKeys',$dataKeys,null); + } + return $dataKeys; + } + + /** + * Returns the value of the data at the specified field. + * If data is an array, TMap or TList, the value will be returned at the index + * of the specified field. If the data is a component with a property named + * as the field name, the property value will be returned. + * Otherwise, an exception will be raised. + * @param mixed data item + * @param mixed field name + * @return mixed data value at the specified field + * @throws TInvalidDataValueException if the data is invalid + */ + protected function getDataFieldValue($data,$field) + { + if(is_array($data)) + return $data[$field]; + else if(($data instanceof TMap) || ($data instanceof TList)) + return $data->itemAt($field); + else if(($data instanceof TComponent) && $data->canGetProperty($field)) + { + $getter='get'.$field; + return $data->$getter(); + } + else + throw new TInvalidDataValueException('basedatalist_datafield_invalid'); } /** -- cgit v1.2.3