JSF2.0学习笔记

最近由于项目原因开始接触了JSF,收到一堆零碎的文档,然后接手代码概览了下程序框架。怎么说呢,给我的印象并不是很好。相对于如今JS等前端框架大行其道,JSF逢出世以来似乎便显得拙笨很多,应用服务器的承载压力太大了!然而,它依然在发展,毕竟,并不是每个项目都能像淘宝那样拥有的海量级别的用户,对于一般公司而言采购一台不错的服务器便游刃有余了。JSF自有它的好处,节约了前端成本,敏捷的开发效率,不失为一个它存在的道理。
由于手头上只有JSF1.X的书籍,所以学习也始于此。列举其下心得:
1、使用Bean来绑定前台组件进行服务器组件化开发,——后台功能很强。
2、primeFaces等有效支持其开发,但别忘记了JSF的UI。
3、每次请求都给bean开辟了内存空间,经测可靠(没有并发数据问题)
4、生命周期有空再看

其次,从官方网站上补充概括了若干条“新特性”,就算是学习到2.0了。
JSF2.0 vs 1.x
add a PROJECT_STAGE setting of Development to web.xml.
By doing this, many errors that would silently fail in JSF 1.x now result in explicit error messages. 

 Don't use @taglib, but instead use xmlns:h="http://java.sun.com/jsf/html". 
Then, use h:head, h:body, and h:form (but not usually f:view) in the page.

you can put @ManagedBean above the class definition.You can also do @ManagedBean(name="someName"). 
Beans are request scoped by default, but there are annotations like @SessionScoped to change the default.

if someMethod returns "foo" and "bar", and there are no explicit navigation rules in faces-config.xml for those outcomes, 
then JSF will assume that they correspond to foo.xhtml and bar.xhtml (from the same folder as form.xhtml),

You can usually use #{myBean.myProperty} instead of <h:outputText value="#{myBean.myProperty}"/>

Add xmlns:f="http://java.sun.com/jsf/core" to the page header.
Inside the start and end tags for h:commandButton, put <f:ajax execute="@form" render="resultId"/>. 
Then, also have <h:outputText value="#{myBean.myProperty}" id="resultId"/>. 
This means that when the button is pressed, all the form elements are sent to the server and executed normally. 

Mere mortals can build custom components
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值