immediate 属性的应用总结

The main purpose of conversion and validation is to ensure values have been properly sanitized before updating model data. Subsequently, when the time comes to invoke application methods to actually do something with that data, you can safely make certain assumptions about the state of your model. Conversion and validation allow you to focus on business logic rather than the tedious qualifications of input data such as null checks, length qualifiers, range boundaries, etc.

It makes sense, then, that conversion and validation processes happen before component data is bound to your backing bean model in the update model data lifecycle phase. As you saw in Figure 1, conversion occurs in the apply request values phase and validation in the process validations phase. These phases are highlighted in Figure 2.


Figure 2. Conversion and validation phases of interest
JSF lifecycle  diagram of conversion and validation phases

About the immediate attribute

Note that the conversion and validation processes outlined in Figure 2 represent the application flow when the UIInput component's immediate attribute is set to false. Were the attribute set to true, conversion and validation would occur earlier in the lifecycle, during the apply request values phase (see Figure 3). A detailed discussion about using the immediate attribute is beyond the scope of this article, but there are instances where it is useful -- such as managing dynamic lists (which you may recall from the previous article in this series) and even bypassing validation altogether (when used with a UICommand component). Can you think of an application where it would be useful to bypass validation completely?

Figure 3 shows where conversion and validation would occur in the JSF application lifecycle were the immediate attribute set to true.


Figure 3. When the immediate attribute is true
A JSF lifecycle  diagram for when the immediate attribute is set to true


Basically, in any scenario where a user must enter data, that data must be validated. If the overall data entry is optional, however, then validation need not occur. One way of working around the validation phase of the JSF lifecycle is to utilize the UICommand component's immediate attribute, which can force the action to be invoked during the apply request values phase before the process validations phase (rather than during the invoke application phase, which occurs after the process validations phase).

The immediate attribute allows you to control page flow through standard navigation rules while bypassing validation altogether. You could implement this technique for specific scenarios such as online wizards with optional steps and/or forms (such as when the user clicks the Skip button to advance to the next view) or in cases where the user cancels out a form for some reason.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值