在线观看亚洲专区,亚洲国产精品成人精品无码区 ,337p日本欧洲亚洲大胆人人http://m.tkk7.com/iamlibo/category/44817.htmlzh-cnFri, 13 Jul 2012 18:30:23 GMTFri, 13 Jul 2012 18:30:23 GMT60JSF2 傳參太爽了http://m.tkk7.com/iamlibo/archive/2012/07/13/383050.htmlLiboLiboFri, 13 Jul 2012 11:42:00 GMThttp://m.tkk7.com/iamlibo/archive/2012/07/13/383050.htmlhttp://m.tkk7.com/iamlibo/comments/383050.htmlhttp://m.tkk7.com/iamlibo/archive/2012/07/13/383050.html#Feedback0http://m.tkk7.com/iamlibo/comments/commentRss/383050.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/383050.html閱讀全文

Libo 2012-07-13 19:42 發表評論
]]>
jsf 2 自定義轉換器打包http://m.tkk7.com/iamlibo/archive/2010/05/07/320311.htmlLiboLiboFri, 07 May 2010 11:23:00 GMThttp://m.tkk7.com/iamlibo/archive/2010/05/07/320311.htmlhttp://m.tkk7.com/iamlibo/comments/320311.htmlhttp://m.tkk7.com/iamlibo/archive/2010/05/07/320311.html#Feedback1http://m.tkk7.com/iamlibo/comments/commentRss/320311.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/320311.htmljsf 2 自定義轉換器  在開發狀態下運行正常(即沒有將代碼打包成jar包),打包后放到WEB-INF/lib目錄下,當使用轉換器時提示不能實例化轉換器。查了一jsf 2 ri 源碼,是在實例化是出現了一個空值,查了半天,涉及的代碼太多。時間關系,只好不打包了。

有知道的交流一下。


Libo 2010-05-07 19:23 發表評論
]]>
轉: JSF2中輕松使用ajax http://m.tkk7.com/iamlibo/archive/2010/05/05/320143.htmlLiboLiboWed, 05 May 2010 12:10:00 GMThttp://m.tkk7.com/iamlibo/archive/2010/05/05/320143.htmlhttp://m.tkk7.com/iamlibo/comments/320143.htmlhttp://m.tkk7.com/iamlibo/archive/2010/05/05/320143.html#Feedback2http://m.tkk7.com/iamlibo/comments/commentRss/320143.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/320143.html JSF2中輕松使用ajax  http://blog.csdn.net/thinkhlin_down/archive/2010/04/15/5488370.aspx

1:使用JSF2提供的ajax的理由

       js兼容性:寫過web應用的朋友都知道,js在各個瀏覽器中的不兼容是出了名的,在IE上運行好好的放到firefox下可能沒法正常運行,或者相反的情況在firefox下正常運行的代碼在IE上無法運行,甚至在IE6下能正常運行的代碼在IE8里面不能正常運行,但是JSF2.0中將所有的不一致都隱藏起來了,開發者或者使用者無需關心這些惱人的問題。

       ajax框架的選擇:當前有許多流行的ajax框架,如jqueryjsondwr等等,但是這些都必須額外添加支持庫而且有些必須進行繁雜的配置,對于注重應用的開發人員來說很不利(別說用那些很多配置的顯示你很高手,那都是自我安慰的一種方式,誰不喜歡簡單的事情!難不成你用這些理由跟你們老板理論去,那你就等著卷鋪蓋走人吧!),而JSF2是內置了ajax功能,能滿足我們絕大部分的需求,所以可以大大的簡化和加速我們項目的進度。

2:最簡單的ajax功能

       如今流行的ajax框架非常多,比如jquerydwr等之類的,但是這些ajax框架(或類似腳本庫)都是單獨提供的,而且使用起來還是相對麻煩,而JSF2提供的ajax功能實現非常簡單,甚至一句js代碼都不用寫就可以完成頁面的無刷新功能。

以下是一個非常簡單的一個使用JSF2標簽并帶有ajax功能的代碼

<h:commandButton action="#{testAjax.validateUser}">

       <f:ajax render="id1">

</h:commandButton>

我們在上面的例子中并沒有看到任何的js代碼,其實JSF2標簽幫我們封裝好了所有的操作,在生成頁面的時候會進行相應的處理,具體的屬性介紹我們下面的內容會詳細講解。

3:以上的例子只是一個非常簡單的功能,能完成一些基本的ajax功能,我們現在編寫一個相對完全一點的示例:

<h:commandButton action="#{testAjax.validateUser}">

       <f:ajax render="id1 id2" execute="id3 id4" event="blur" onevent="showFire" />

</h:commandButton>

屬性說明:

屬性名稱

屬性說明

render

頁面上需要刷新的元素的id,如果有多個可以用空格隔開,示例中就是有id1 id2,中間使用空格隔開,前提是我們的元素必須要有一個id屬性,比如一個輸入框<input type="text" id="id1" value=""/>

execute

需要提交給服務器端的參數的id,如果有多個用空格隔開,比如說更新id1時,需要傳入一個輸入框idid3的元素,那么可以用execute="id3",其實還可以使用@符號來操作,有@this表示當前元素;@form表示此元素所在表單(form)下的所有的元素;@none表示不提交任何元素;@all表示提交頁面所有JSF的可提交的元素。

event

ajax事件觸發的條件,比如我們上一例子就是使用了event="blur",表示當blur事件發生時觸發ajax事件(blur只是舉例,可以使用的有action, blur, change, click, dblclick, focus, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, mouseup, select),如果沒有指定則使用默認的事件觸發,默認的事件是actionaction其實不是js中有的事件,是指任何方式觸發調用,如點擊也能觸發action事件。

onevent

ajax事件相應完成后執行的js函數,比如說我們上面示例代碼有onevent="showFire",這個函數帶可以帶至多一個參數,這個參數是ajax時間觸發后返回的結果DOM對象(并不是我們調用java代碼中的方法返回的參數),在ajax事件響應完成后即調用showFire這個函數,示例如下代碼

<script type="text/javascript">

       function showFire() {

              alert("回調函數事件已經觸發");

       }

</script>

<h:form>

       <h:outputText id="id1" value="#{ajaxTest.number}"/>

       <h:commandButton value="數字增加" action="#{testAjax.count}">

              <f:ajax render="number" onevent="showFire"/>

       </h:commandButton>

</h:form>

...

Java代碼

...

@ManagedBean

@ViewScoped

public class AjaxTest implements Serializable {

   

    private int number;

    public void count() {

        number++;

    }

       //getter and setter

       ...

}

listener

此屬性是指ajax事件觸發后調用的managedbean的方法,其實作用很明顯,比如說我們這里不用按鈕之類的標簽,只是需要當我們輸入某個數據的時候觸發一個ajax事件,這個屬性就顯得很重要了。示例如下:

JSF頁面代碼

...

    <h:head>

        <title>JSF2.0 ajax測試</title>

        <script type="text/javascript">

            var temp = 0;

            function showFire() {

                alert("響應函數!");

            }

        </script>

    </h:head>

    <h:body>

        <h:form>

            <h:outputText id="id1" value="#{ajaxTest.number}"/>

            <h:inputText>

                <f:ajax render="id1" event="keyup" onevent="showFire" listener="#{ajaxTest.count}"/>

            </h:inputText>

        </h:form>

    </h:body>

...

Java代碼

...

@ManagedBean

@ViewScoped

public class AjaxTest implements Serializable {

   

    private int number;

    public void count() {

        number++;

    }

       //getter and setter

       ...

}

listener屬性的代碼作用就是調用AjaxTest類中的count方法,使數字加一,我們也可以延伸一下作用,比如說注冊信息的時候,輸入的用戶名檢查是否重復,當我們輸入的時候就實時檢測即可。

注:此回調函數showFire會被執行三次,但是通過監控軟件ajax事件觸發后只提交了一次數據請求,所以具體的問題出現在客戶端,由于資料相對較少暫時不做解釋。



Libo 2010-05-05 20:10 發表評論
]]>
JSF2.0 Converterhttp://m.tkk7.com/iamlibo/archive/2010/04/24/319265.htmlLiboLiboSat, 24 Apr 2010 07:05:00 GMThttp://m.tkk7.com/iamlibo/archive/2010/04/24/319265.htmlhttp://m.tkk7.com/iamlibo/comments/319265.htmlhttp://m.tkk7.com/iamlibo/archive/2010/04/24/319265.html#Feedback0http://m.tkk7.com/iamlibo/comments/commentRss/319265.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/319265.html

JSF2.0 日期轉換

Jsf RI 包提供默認的日期轉換器 <f: convertDateTime /> 但在使用時發現從數據讀出數據顯示的時候會少一天,比如:數據庫中的日期是2010-4-24 在經過轉換器前還是這個日期,但轉換后顯示到界面上時就會顯示2010-4-23 ,無論設置格式還是時區都無效。

既然不好用就自定義一個轉換器,好在JSF2.0 自定義轉換器也非常的方便了

整個代碼如下:

import java.text.ParseException;
import java.util.Date;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import cn.xiangyunsoft.utils.DateUtils;
import cn.xiangyunsoft.utils.StringUtils;

@FacesConverter(value 
= "dateConverter")
public class ConvertDate implements Converter {

    
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        
if (StringUtils.isNotEmpty(arg2)) {
            
try {
                
return DateUtils.parseDate(arg2);
            } 
catch (ParseException e) {
                e.printStackTrace();
            }
        }
        
return null;
    }

    
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        
if (arg2!=null){
            
return DateUtils.format((Date) arg2, "yyyy-MM-dd");
        }
        
return null;
    }

}

其中DateUtils 類就是常用的日期和字符串的轉換方法。

XHTML 使用時如下:

<h:inputText id="#{cc.attrs.id}" value="#{cc.attrs.value}"
        onkeydown
="ctlent(event);" styleClass="#{cc.attrs.styleClass}">
        
<!--<f:convertDateTime pattern="yyyy-MM-dd" locale="zh-CN"/>-->
        
<f:converter converterId="dateConverter" />
    
</h:inputText>





Libo 2010-04-24 15:05 發表評論
]]>
JSF2.0 與Spring 3.0 集成http://m.tkk7.com/iamlibo/archive/2010/04/24/319264.htmlLiboLiboSat, 24 Apr 2010 07:03:00 GMThttp://m.tkk7.com/iamlibo/archive/2010/04/24/319264.htmlhttp://m.tkk7.com/iamlibo/comments/319264.htmlhttp://m.tkk7.com/iamlibo/archive/2010/04/24/319264.html#Feedback2http://m.tkk7.com/iamlibo/comments/commentRss/319264.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/319264.html

JSF2.0 與Spring 3.0 集成

同以前的JSF1.2Spring2.5集成類似,只是有一些類名的變化。

web.xml 代碼如下:

<context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>WEB-INF/applicationContext.xml</param-value>
    
</context-param>
    
<listener>
        
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    
</listener>
    
<listener>
        
<listener-class> org.springframework.web.context.ContextLoaderListener
            
</listener-class>
    
</listener>
    
<listener>
        
<listener-class>
            org.springframework.web.context.request.RequestContextListener
</listener-class>
    
</listener>
    
<servlet>
        
<servlet-name>Faces Servlet</servlet-name>
        
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        
<load-on-startup>1</load-on-startup>
    
</servlet>
    
<servlet-mapping>
        
<servlet-name>Faces Servlet</servlet-name>
        
<url-pattern>*.xhtml</url-pattern>
    
</servlet-mapping>
    
<servlet-mapping>
        
<servlet-name>Faces Servlet</servlet-name>
        
<url-pattern>*.jsf</url-pattern>
    
</servlet-mapping>
    
<context-param>
        
<param-name>javax.faces.PROJECT_STAGE</param-name>
        
<param-value>Development</param-value>
    
</context-param>
    
<welcome-file-list>
        
<welcome-file>index.html</welcome-file>
    
</welcome-file-list>


Faces-config.xml中加入:

<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>

JSF1.21.2以前是加入

<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>

Spring 的配置文件就正常配置就可以了。

ApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx
="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation
="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
>
    
<!--
        <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="WEB-INF/jdbc.properties" /> </bean>
    
-->
    
<!-- hibernate sessionFactory -->
    
<context:annotation-config/>
    
<context:component-scan base-package="cn.xiangyunsoft" />
    
<bean id="sessionFactory"
        class
="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        
<property name="hibernateProperties" value="classpath:hibernate.properties" />
        
<property name="configLocations">
            
<list>
                
<!-- 使用hibernate.cfg.xml配置文件 -->
                
<value>classpath:hibernate.cfg.xml
                
</value>
            
</list>
        
</property>
    
</bean>
    
<!-- 配置事務管理 -->
    
<!-- 事務通知類 -->
    
<!--
        <bean id="profiler"
        class="cn.xiangyunsoft.business.service.SimpleProfiler"> order
        值可以決定通知的先后順序 ,與后面的order的值的大小,決定了是先通知再執行,還是先執行再通知 <property
        name="order" value="2" /> </bean>
    
-->
    
<bean id="transactionManager"
        class
="org.springframework.orm.hibernate3.HibernateTransactionManager">
        
<property name="sessionFactory" ref="sessionFactory" />
    
</bean>
    
<aop:config>
        
<!-- 此處的IService 是表示對所有實現IService接口的類管理事務 -->
        
<aop:advisor
            
pointcut="execution(* cn.xiangyunsoft.*.service..*ServiceImpl.*(..))"
            advice-ref
="txAdvice" />
        
<!--
            加入之后事務不起作用> <aop:aspect id="profilingAspect" ref="profiler">
            <aop:pointcut id="serviceMethodWithReturnValue"
            expression="execution(*
            cn.xiangyunsoft.*.service..*ServiceImpl.*(..))" />
            <aop:after-throwing method="profile"
            pointcut-ref="serviceMethodWithReturnValue" /> </aop:aspect
        
-->
    
</aop:config>
    
<tx:advice id="txAdvice" transaction-manager="transactionManager">
        
<!-- the transactional semantics -->
        
<tx:attributes>
            
<!-- 以get、find、load開頭的方法是只讀事務 -->
            
<tx:method name="*" read-only="true" />
            
<!--<tx:method name="find*" read-only="true" />-->
            
<!--<tx:method name="load*" read-only="true" />-->
            
<!-- 其他方法是默認,事務隔離級別為:保證一個事務修改的數據提交后才能被另外一個事務讀取 -->
            
<tx:method name="save*" isolation="REPEATABLE_READ"
                propagation
="REQUIRED" />
            
<tx:method name="delete*" isolation="REPEATABLE_READ"
                propagation
="REQUIRED" />
                
        
</tx:attributes>
    
</tx:advice>
</beans>


一個注入Spring bean 的 JSF bean 代碼如下:

@ManagedBean(name = ClassItemBean.NAME)
public class ClassItemBean {

    
public static final String NAME = "classItemBean";

    
/*
     *在spring 中配置的service.
     
*/
    @ManagedProperty(name 
= "classItemService", value = "#{classItemService}")
    
private ClassItemService classItemService;

    
public void setClassItemService(ClassItemService classItemService) {
        
this.classItemService = classItemService;
    }

    
public String hello() {
        System.out.println(
"hello." + classItemService);
        Object obj 
= classItemService.get(ClassItem.class"01");
        System.out.println(
"obj = " + obj);
        
return null;
    }
}


這樣集成就完畢了。很簡單,很強大。






Libo 2010-04-24 15:03 發表評論
]]>
JSF 2 Navigationhttp://m.tkk7.com/iamlibo/archive/2010/04/24/319263.htmlLiboLiboSat, 24 Apr 2010 06:53:00 GMThttp://m.tkk7.com/iamlibo/archive/2010/04/24/319263.htmlhttp://m.tkk7.com/iamlibo/comments/319263.htmlhttp://m.tkk7.com/iamlibo/archive/2010/04/24/319263.html#Feedback0http://m.tkk7.com/iamlibo/comments/commentRss/319263.htmlhttp://m.tkk7.com/iamlibo/services/trackbacks/319263.html

JSF 2.0 Navigation

 

JSF 1.X 中使用導航需要在faces-config.xml 加入這樣的代碼:

 

<navigation-rule>

  
<navigation-case>

    
<from-view-id>/pages/login.xhtml</from-view-id>

    
<outcome>main</outcome>

    
<to-view-id>/pages/main.xhtml</to-view-id>

  
</navigation-case>

</navigation-rule>

JSF 2 中完全可以不用配置。


<h:commandButton id="loginButton" 
  value
="#{msgs.loginButtonText}" action="main"/>

點擊按鈕會轉到main.xhtmlJSF 會在當前目錄中查找main.xhtml
也可以使用絕對地址:
<h:commandButton id="loginButton"

  value
="#{msgs.loginButtonText}"

  action
="/pages/main"/>

 

默認情況下JSF 會從一頁面forwards到另一個頁面。也可以使用redirect轉到另一個頁面。


<h:commandButton id="loginButton"

  value
="#{msgs.loginButtonText}"

  action
="/pages/main?faces-redirect=true"/>

相比 JSF1.2 要簡單得多!



Libo 2010-04-24 14:53 發表評論
]]>
主站蜘蛛池模板: 国产亚洲av片在线观看16女人 | 日本免费网址大全在线观看| 国产成人精品日本亚洲网址| 可以免费观看的一级毛片| 国产精品免费看久久久香蕉| 亚洲视频网站在线观看| 在线观看亚洲免费| 美女被cao网站免费看在线看| 亚洲国产日韩视频观看| 国产亚洲精品成人AA片新蒲金| 亚洲一区二区三区免费在线观看 | 88xx成人永久免费观看| 粉色视频在线观看www免费| 亚洲AV无码专区在线播放中文| 在线观看免费污视频| 美女视频黄a视频全免费网站色窝| 亚洲人成自拍网站在线观看| 亚洲国产精品一区二区成人片国内 | 国产V亚洲V天堂无码| 成年女人视频网站免费m| 大地资源网高清在线观看免费| 亚洲最大中文字幕无码网站| 中文亚洲AV片在线观看不卡| 免费无码黄动漫在线观看| 免费A级毛片无码A∨| 一级午夜a毛片免费视频| 亚洲色中文字幕在线播放| 亚洲avav天堂av在线不卡| 亚洲精品国产精品乱码不卡| 成年女人免费碰碰视频| 亚洲免费精彩视频在线观看| 无遮挡国产高潮视频免费观看| 国产人成亚洲第一网站在线播放| 亚洲狠狠综合久久| 亚洲精品无码成人AAA片| 又大又粗又爽a级毛片免费看| 毛片免费全部免费观看| 亚洲视频免费在线播放| 永久免费AV无码网站国产| 国产大片免费天天看| 黄色一级视频免费|