1、Managed beans的编写
1)采用注释的方式进行实例化
@ManagedBean/@ManagedBean(name="beanName")
@SessionScoped
public class className{}
2)在faces-config.xml文件进行配置
<managed-bean>
   <managed-bean-name>userBean</managed-bean-name>
   <managed-bean-class>完全类路径</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
2、给bean的属性注入值
1、采用注释方式注入
@ManagedBean
@SessionScoped
public class UserBean {

@ManagedProperty(value="Jane")
private String firstName;
@ManagedProperty(value="Doe")
private String lastName;

public String getFirstName() {
   return firstName;
  }
public void setFirstName(String firstName) {
  this.firstName = firstName;
}
public String getLastName() {
   return lastName;
  }
public void setLastName(String lastName) {
  this.lastName = lastName;
}
}
2、采用xml方式注入(fancs.config.xml)<managed-bean>
<managed-bean-name>userBean</managed-bean-name>
  <managed-bean-class>完全类路径</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
   <property-name>firstName</property-name>
   <value>Jane</value>
  </managed-property>
  <managed-property>
   <property-name>lastName</property-name>
   <value>Doe</value>
  </managed-property>
</managed-bean>
2.1、给list类型的属性注入值
<managed-bean>
...
<managed-property>
  <property-name>sportsInterests</property-name>
   <list-entries>
    <value>Cycling</value>
    <value>Running</value>
    <value>Swimming</value>
    <value>Kayaking</value>
    ...
   </list-entries>
  </managed-property>
</managed-bean>
注:</list-entries>默认的list泛型是String类型,如果要注入其他类型可以这样使用:
<managed-bean>
...
<managed-property>
<property-name>racePlacement</property-name>
  <list-entries>
   <value-class>java.lang.Integer</value-class>
   <value>23</value>
   <value>12</value>
   <value>3</value>
   <value>1</value>
    ...
  </list-entries>
</managed-property>
</managed-bean>
  Element        Description
。。<managed-property>    Same as before, the parent element for managed properties.

。。<property-name>       The name of the property, which must be of type array
         or java.util.List.
        
。。<property-class>    JSF uses the default type of ArrayList, but any other list concrete
          class could be specified here.
         
。。<list-entries>(1 to N)   Parent element of the <value-class>, list values defined in multiple
         <value> or <null-value> elements.
        
。。<value-class>     When not using the default list type of java.lang.String, one must
          specify the list item data type here. (Optional)
         
。。<value> or <null-value>  The <value> element provides the value with which to set the
             property. When initializing a property to a null value, a <null-value>
         tag is used instead.
         Note: The <null-value> element cannot be used for primitive data types.
注:list的类型可以这样读
  <h:outputText value="#{userBean.sportsInterests[0]}"/>
2.2给map类型的属性注入
<managed-bean>
...
<managed-property>
   <property-name>sportsInterests</property-name>
    <map-entries>
     <map-entry>
      <key>Cycling</key>
      <value>Any competitive athletic event where a bicycle is used.</value>
      </map-entry>
     <map-entry>
      <key>Running</key>
<value>Any competitive athletic event where the competitors are running or jogging.</value>
     </map-entry>
     <map-entry>
      <key>Swimming</key>
      <value>Any competitive athletic event where the competitors are swimmming.</value>
     </map-entry>
     <map-entry>
      <key>Kayaking</key>
      <value>Any competitive athletic event where the competitors use a kayak.</value>
     </map-entry>
    </map-entries>
    ...
   </managed-property>
</managed-bean>
注:map的类型可以这样读:
<h:outputText value="#{userBean.sportsInterests['Swimming']}"/>
   Element       Description
。。<managed-property>    Same as before, the parent element for managed properties.

。。<property-name>     The name of the property.

。。<property-class>    JSF uses the default type of HashMap, but any other Map concrete
         class could be specified here.
        
。。<map-entries>     Parent element of <key-class>, <value-class>, and Map entries.

。。<key-class>      Element specifying data type of the keys used in the map. When
         not specified, a java.lang.String is used as a default. (Optional)
        
。。<value-class>     Element specifying data type of the values used in the map.
         When not specified, a java.lang.String is also used as a default.(Optional)
        
。。<map-entry>(1 to N)    Parent element to a Map key/value element pair.

。。<key>       The key value used to look up an associated value.

。。<value>or<null-value>  The <value> element that is retrieved when the associated key
         is supplied. To initialize a Map property to a null value, a <nullvalue> tag is used.
         Note: The <null-value> element cannot be used for primitive data types.

3、Controlling Managed Bean Life Spans
#{userBean }
#{userBean }
#{userBean }
#{userBean }
1)@NoneScoped
像这样写在同一个页面中,只有一个请求,但是会实例化四次bean。
2)@RequestScoped
实例化一次,每次请求得到的对象都是不同的。即请求一次实例化一次。
3)@ViewScoped
  在同一页面内是同一对象的,但通过浏览器去刷新,每次都会实例化。
  4)@SessionScoped
  一次会话内都是同一对象,除非session失效或者超时。
  5)@ApplicationScoped
  存活于整个应用服务。

Managed Beans相关推荐

  1. Managing Spring beans with JMX

    文章目录 This chapter covers Exposing Spring beans as managed beans 将Spring bean暴露为MBean Remotely managi ...

  2. JavaServer Faces技术

    一.JSF是构建Java Web程序的服务器端的组件框架,包括: 1)一个API,用来表示组件及管理他们的状态:处理事件:服务器端:数据转换:定义页面导航:支持国际化和可访问性:并且提供对以上功能AP ...

  3. WLST - Presentation Transcript

    2019独角兽企业重金招聘Python工程师标准>>> WLST Bhavya Siddappa May 30, 2008 Topics of Discussion What is ...

  4. spring源码分析之spring jmx

    JMX架构定义: https://docs.oracle.com/javase/8/docs/technotes/guides/jmx/overview/architecture.html Archi ...

  5. Java中JMX管理器的作用,项目中有什么具体使用?

    作者:wuxinliulei 链接:https://www.zhihu.com/question/36688387/answer/68667704 来源:知乎 著作权归作者所有.商业转载请联系作者获得 ...

  6. [转:作者: 出处:javaresearch ]选择JSF不选Struts的十大理由

    总的来说,我建议在新项目中优先考虑JSF.虽然常常有一些商业上的因素迫使我们为现有的项目选择了Struts,而且那些解决方案还有待考验 ,但是,让我们面对一个事实:JSF比Struts好多了. 下面是 ...

  7. adf时间作用域_ADF:在任务流终结器中支持bean作用域

    adf时间作用域 介绍 当我们需要在任务流消失之前做一些最终工作(干净的资源,紧密的连接等)时,这是使用任务流终结器的非常普遍的建议做法. 和往常一样,我们使用在任务流中声明的托管bean. 托管Be ...

  8. 评论:Arun Gupta撰写的“ Java EE 6 Pocket Guide”

    这是我很高兴写的评论. 我的朋友阿伦(Arun)发布了Java EE 6袖珍指南,该指南将在您订购时尽早提供. 我很早就知道这本书,因为我很乐意对其进行回顾,也感谢有机会为本书做出一点贡献! Kind ...

  9. ADF:在任务流终结器中支持bean作用域

    介绍 当我们需要在任务流消失之前完成一些最终工作(干净的资源,紧密的连接等)时,这是使用任务流终结器的非常普遍的推荐做法. 和往常一样,我们使用在任务流中声明的托管bean. 托管Bean可以具有不同 ...

最新文章

  1. 利用Advanced Installer将asp.netMVC连同IIS服务和mysql数据库一块打包成exe安装包
  2. 【译】光线跟踪:理论与实现(一) 简介
  3. Redis的安装与部署
  4. 对数据库连接池的理解
  5. python截图模块_pyscreenshot
  6. 创建sprite 组
  7. 第四次作业——04树
  8. 写好PPT的四大要点
  9. 511遇见易语言教程API模块制作cmd复制文件
  10. wmic java_Java执行wmic命令获取系统环境变量
  11. 基于SSM+SpringBoot+Vue+ElmentUI实现公司案件管理系统
  12. CentOS系统编译部署nginx-http-flv-module模块搭建流媒体服务器
  13. halcon 缺陷检测 表面凸点检测
  14. 金多多点评上塘路包揽大金融
  15. qcloud-ocr
  16. Android开发所需要的矩阵知识
  17. 商标注册计算机软件app属于第几类,软件商标属于第几类?
  18. Android 模仿淘宝历史记录,记录存在手机内
  19. 北京市工作居住证办理流程以及资料
  20. sql语句:简写拼音查询

热门文章

  1. 少年上人号怀素下一句,这首诗本是咏怀素的,却在结尾幽了张旭一默,我白够狂︱浅雨
  2. MIT oracle ma 信号线,美国 MIT Oracle MA-X Phono唱臂线 独家Multipole技术
  3. 转载:Think in AngularJS:对比jQuery和AngularJS的不同思维模式(大漠穷秋)
  4. 摩托罗拉的新一代智能家庭和婴儿监护亮相香港电子产品展
  5. 算法与数据结构(邓俊辉)第一章
  6. JCA Overview
  7. linux中sed提取ip,通过sed命令获取IP地址
  8. amd显卡测试大风车软件md,知之实验室 篇三:大家好才是真的好!免费显卡升级工具AMD FSR技术研究测试...
  9. echarts地图功能实现及坐标定位
  10. GAN之野狼DiscoGAN