JSF 要点

 

1. Beans are request scoped by default. One request one bean.

 

 Managed beans typically have three parts

1.  Bean properties (i.e, pairs of getter and setter methods)

 

  • One pair for each input element
  • Setter methods called automatically by JSF when form methods called automatically by JSF when form submitted. Called before action controller method.

2. Action controller methods

 

  • Often only one but could be several if the same form has only one, but could be several if the same form has multiple buttons
  • Action controller method (corresponding to the button that was was pressed) called automatically by JSF pressed) called automatically by JSF

 

3 .  Placeholders for results data

 

  • Not automatically called by JSF: to be filled in by action controller method based on results of business logic.
  • Needs a getter method so value can be output in result page, but not required to have a setter method



 @RequestScoped
– Default. Make a new instance for every HTTP request. 
Since beans are also used for initial values in input form, 
this this means bean is generally instantiated twice (once means bean is generally instantiated twice (once
when form is displayed, once when form is submitted).
@SessionScoped
– Put bean in session scope. If same user with same cookie 
returns before session timeout, same bean instance is 
used. used. You should make bean Serializable. You should make bean Serializable.
@ApplicationScoped
– Put bean in app p y pplication scope. Shared by all users. Bean 
either should have no mutable state or you must carefully 
synchronize access

HTTP request object and response object
• Static methods
– If they are needed, use static method calls to get them
ExternalContext context =
FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request =
(HttpServletRequest)context.getRequest();
HttpServletResponse response =
(HttpServletResponse)context.getResponse();


 You can instantiate beans at app load time
– @ManagedBean(eager=true)
@ApplicationScoped
public class SomePojo { … }
• This This is useful for the bean that you inject into the main bean. The injected is useful for the bean that you inject into the main bean. The injected
bean is often something shared like a loo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值