2008.04.12 摘自 JSF in action Initializing simple properties Page/148
1. 只有有set及get(可读写)方法的属性才可以由Managed Bean Creation facility 管理,如果属性没有在.xml文件中配置,则保持其初始值.
2. 必须标识出属性的名称和对其赋的值.<property-name>,<value>这两项.
3.结构示意图为:
Figure 3.7 You can initialize managed bean properties with the <managedproperty> element (each <managed-bean> element can have zero or more <managed-property> elements). Its optional elements are <description>,
<display-name>, <icon>, and <property-class>. The required elements are <property-name> and either <value> or <null-value>.
4. 可以看出<managed-property>是嵌入在<managed-bean>中的,<managed-property>中包含的<property-name>和<value>或<null-value>是必须的,<property-class>指示说属性的类型(java类或者是primitive type),这个不是JSF必须的,因为JSF通过自己的方式指出属性的类型.范例为:
<managed-bean>
<managed-bean-name>brokeUser</managed-bean-name>
<managed-bean-class>org.jia.examples.UserBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>firstName</property-name>
<value>Joe</value>
</managed-property>
<managed-property>
<property-name>lastName</property-name>
<value>Broke</value>
</managed-property>
<managed-property>
<property-name>balance</property-name>
<value>0</value>
</managed-property>
<managed-property>
<property-name>favoriteAnimal</property-name>
<null-value/>
</managed-property>
</managed-bean>