注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

流星永恒的博客

JSF,Facelets,Rich(Prime)Faces,和java的笔记

 
 
 

日志

 
 

JSTL with JSF 2.1.x  

2014-02-17 18:02:29|  分类: jsf2.0 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

From this topic: http://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense


JSTL tags are taghandlers and they are executed during view build time, while JSF UI components are executed during view render time. Note that JSF's own <f:xxx> and <ui:xxx> tags which do notextend UIComponent (i.e. everything except of <f:param> and <f:selectItem(s)> and all those tags having a rendered attribute) are also taghandlers. Also, the id and binding attributes of JSF UI components are evaluated during view build time. Thus the below answer applies to them as well.

The view build time is that moment when the XHTML/JSP file is to be parsed and converted to a JSF component tree which is then stored as UIViewRoot of the FacesContext. The view render time is that moment when the JSF component tree is about to generate HTML, starting withUIViewRoot#encodeAll(). So: JSF UI components and JSTL tags doesn't run in sync as you'd expect from the coding. You can visualize it as follows: JSTL runs from top to bottom first, producing the JSF component tree, then it's JSF's turn to run from top to bottom again, producing the HTML output. This may lead to unexpected results when using JSTL tags in for example JSF iterating components like<h:dataTable><ui:repeat>, etc, or when JSTL tag attributes depend on results of JSF events like preRenderView or submitted form values in the model.

JSTL tags should be used carefully in Mojarra versions older than 2.1.18. Before this version, they don't work well together with view scoped beans when partial state saving is turned on (as by default). When you reference a view scoped bean in an attribute of a JSTL tag, then it will be newly recreated instead of retrieved from the view tree (simply because the complete view tree isn't available yet at the point JSTL runs). If you're expecting or storing some state in the view scoped bean by a JSTL tag attribute, then it won't return the value you expect, or it will be "lost" in the real view scoped bean which is restored after the view tree is built.

In a nutshell: Use JSTL tags to control flow of JSF component tree building. Use JSF UI components to control flow of HTML output generation. Do not bind the var of iterating JSF components to JSTL tag attributes. Do not rely on JSF events in JSTL tag attributes. Use at least Mojarra 2.1.18 to have the chicken-egg issue with view scope fixed, otherwise you must turn off partial state saving.


A more useful link about exlaintation about jstl and facelets:
  评论这张
 
阅读(537)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017