jsf2.0---jsf的新特性


  jsf2标准通过jcp的定版已经快一年了。相比Jsf1.x有不少的改动。
  比较显著的特点是Bean可以通过注解的方式来配置,少写很多xml配置文件。
 
   对ajax有显著的支持。下面通过简单的一个例子来看看jsf2。

首先我们定义Bean.

 

注意哦,如果在jsf1.2里,你必须要配置这个bean到face-config.xml中的。

但是在jsf2中,可以在java类中直接使用@ManagedBean就可以了。

然后定义一个页面index.xhtml.代码如下

-----------------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
    <title>Ajax</title>
</h:head>
<h:body>
    <h:form id="form1" prependId="false">
        <h:outputScript name="jsf.js" library="javax.faces" target="head"/>
        <h:outputText id="out1" value="#{count.count}"/>
        <br/>
        <!-- Increment the counter on the server, and the client -->
        <h:commandButton id="button1" value="Count"
                         onclick="jsf.ajax.request(this, event, {execute: this.id, render: 'out1'}); return false;"/>
        <br/>
        <!-- Resets the counter -->
        <h:commandButton id="reset" value="reset"
                            onclick="jsf.ajax.request(this, event, {execute:'reset', render: 'out1'}); return false;"
                            actionListener="#{count.reset}"/>
    </h:form>
</h:body>
</html>

---------------------------------------------------------------------------------

大家在netbeans6.8当中glassfish2中去运行看看。

可以使用ajax无刷新的方式改变值。

效果图如下:

可以实现ajax无须刷新就可以改变数字的值。

 

 

posted @ 2010-06-07 16:53  xujie  Views(486)  Comments(0)    收藏  举报