Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * THiddenField class file.
4
 *
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
 * @link http://www.xisc.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
9
 * @version $Id: THiddenField.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Web.UI.WebControls
11
 */
12
 
13
/**
14
 * THiddenField class
15
 *
16
 * THiddenField displays a hidden input field on a Web page.
17
 * The value of the input field can be accessed via {@link getValue Value} property.
18
 * If upon postback the value is changed, a {@link onValueChanged OnValueChanged}
19
 * event will be raised.
20
 *
21
 * @author Qiang Xue <qiang.xue@gmail.com>
22
 * @version $Id: THiddenField.php 2541 2008-10-21 15:05:13Z qiang.xue $
23
 * @package System.Web.UI.WebControls
24
 * @since 3.0
25
 */
26
class THiddenField extends TControl implements IPostBackDataHandler, IValidatable, IDataRenderer
27
{
28
	private $_dataChanged=false;
29
	private $_isValid=true;
30
 
31
	/**
32
	 * @return string tag name of the hidden field.
33
	 */
34
	protected function getTagName()
35
	{
36
		return 'input';
37
	}
38
 
39
	/**
40
	 * Sets focus to this control.
41
	 * This method overrides the parent implementation by forbidding setting focus to this control.
42
	 */
43
	public function focus()
44
	{
45
		throw new TNotSupportedException('hiddenfield_focus_unsupported');
46
	}
47
 
48
	/**
49
	 * Renders the control.
50
	 * This method overrides the parent implementation by rendering
51
	 * the hidden field input element.
52
	 * @param THtmlWriter the writer used for the rendering purpose
53
	 */
54
	public function render($writer)
55
	{
56
		$uniqueID=$this->getUniqueID();
57
		$this->getPage()->ensureRenderInForm($this);
58
		$writer->addAttribute('type','hidden');
59
		if($uniqueID!=='')
60
			$writer->addAttribute('name',$uniqueID);
61
		if($this->getID()!=='')
62
			$writer->addAttribute('id',$this->getClientID());
63
		if(($value=$this->getValue())!=='')
64
			$writer->addAttribute('value',$value);
65
 
66
		if($this->getHasAttributes())
67
		{
68
			foreach($this->getAttributes() as $name=>$value)
69
				$writer->addAttribute($name,$value);
70
		}
71
 
72
		$writer->renderBeginTag('input');
73
		$writer->renderEndTag();
74
	}
75
 
76
	/**
77
	 * Loads hidden field data.
78
	 * This method is primarly used by framework developers.
79
	 * @param string the key that can be used to retrieve data from the input data collection
80
	 * @param array the input data collection
81
	 * @return boolean whether the data of the component has been changed
82
	 */
83
	public function loadPostData($key,$values)
84
	{
85
		$value=$values[$key];
86
		if($value===$this->getValue())
87
			return false;
88
		else
89
		{
90
			$this->setValue($value);
91
			return $this->_dataChanged=true;
92
		}
93
	}
94
 
95
	/**
96
	 * Returns a value indicating whether postback has caused the control data change.
97
	 * This method is required by the IPostBackDataHandler interface.
98
	 * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
99
	 */
100
	public function getDataChanged()
101
	{
102
		return $this->_dataChanged;
103
	}
104
 
105
	/**
106
	 * Returns the value to be validated.
107
	 * This methid is required by IValidatable interface.
108
	 * @return mixed the value of the property to be validated.
109
	 */
110
	public function getValidationPropertyValue()
111
	{
112
		return $this->getValue();
113
	}
114
 
115
	/**
116
	 * Returns true if this control validated successfully.
117
	 * Defaults to true.
118
	 * @return bool wether this control validated successfully.
119
	 */
120
	public function getIsValid()
121
	{
122
	    return $this->_isValid;
123
	}
124
	/**
125
	 * @param bool wether this control is valid.
126
	 */
127
	public function setIsValid($value)
128
	{
129
	    $this->_isValid=TPropertyValue::ensureBoolean($value);
130
	}
131
 
132
	/**
133
	 * Raises postdata changed event.
134
	 * This method calls {@link onValueChanged} method.
135
	 * This method is primarly used by framework developers.
136
	 */
137
	public function raisePostDataChangedEvent()
138
	{
139
		$this->onValueChanged(null);
140
	}
141
 
142
	/**
143
	 * This method is invoked when the value of the {@link getValue Value} property changes between posts to the server.
144
	 * The method raises 'OnValueChanged' event to fire up the event delegates.
145
	 * If you override this method, be sure to call the parent implementation
146
	 * so that the attached event handlers can be invoked.
147
	 * @param TEventParameter event parameter to be passed to the event handlers
148
	 */
149
	public function onValueChanged($param)
150
	{
151
		$this->raiseEvent('OnValueChanged',$this,$param);
152
	}
153
 
154
	/**
155
	 * @return string the value of the THiddenField
156
	 */
157
	public function getValue()
158
	{
159
		return $this->getViewState('Value','');
160
	}
161
 
162
	/**
163
	 * Sets the value of the THiddenField
164
	 * @param string the value to be set
165
	 */
166
	public function setValue($value)
167
	{
168
		$this->setViewState('Value',$value,'');
169
	}
170
 
171
	/**
172
	 * Returns the value of the hidden field.
173
	 * This method is required by {@link IDataRenderer}.
174
	 * It is the same as {@link getValue()}.
175
	 * @return string value of the hidden field
176
	 * @see getValue
177
	 * @since 3.1.0
178
	 */
179
	public function getData()
180
	{
181
		return $this->getValue();
182
	}
183
 
184
	/**
185
	 * Sets the value of the hidden field.
186
	 * This method is required by {@link IDataRenderer}.
187
	 * It is the same as {@link setValue()}.
188
	 * @param string value of the hidden field
189
	 * @see setValue
190
	 * @since 3.1.0
191
	 */
192
	public function setData($value)
193
	{
194
		$this->setValue($value);
195
	}
196
 
197
 
198
	/**
199
	 * @return boolean whether theming is enabled for this control. Defaults to false.
200
	 */
201
	public function getEnableTheming()
202
	{
203
		return false;
204
	}
205
 
206
	/**
207
	 * @param boolean whether theming is enabled for this control.
208
	 * @throws TNotSupportedException This method is always thrown when calling this method.
209
	 */
210
	public function setEnableTheming($value)
211
	{
212
		throw new TNotSupportedException('hiddenfield_theming_unsupported');
213
	}
214
 
215
	/**
216
	 * @param string Skin ID
217
	 * @throws TNotSupportedException This method is always thrown when calling this method.
218
	 */
219
	public function setSkinID($value)
220
	{
221
		throw new TNotSupportedException('hiddenfield_skinid_unsupported');
222
	}
223
}
224