亚洲另类少妇17p,国产成人亚洲综合一区,亚洲国产高清在线http://www.tkk7.com/xiaosilent/category/18264.htmlWaste of time is the most extravagant and costly of all expenses.<BR><BR><a href="mailto:xiaosilent@gmail.com"><img src="http://www.tkk7.com/images/blogjava_net/xiaosilent/16063/o_mail.png" title="Contact me via xiaosilent@gmail.com" alt="xiaosilent@gmail.com"></a>zh-cnMon, 21 Apr 2008 19:45:09 GMTMon, 21 Apr 2008 19:45:09 GMT60MyEclipse 6.0.1 注冊碼生成類http://www.tkk7.com/xiaosilent/archive/2008/04/21/194650.htmlxiaosilentxiaosilentMon, 21 Apr 2008 15:33:00 GMThttp://www.tkk7.com/xiaosilent/archive/2008/04/21/194650.htmlhttp://www.tkk7.com/xiaosilent/comments/194650.htmlhttp://www.tkk7.com/xiaosilent/archive/2008/04/21/194650.html#Feedback0http://www.tkk7.com/xiaosilent/comments/commentRss/194650.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/194650.html閱讀全文

xiaosilent 2008-04-21 23:33 發表評論
]]>
Ubuntu 8.04 Eclipse MyEclipse 出現的問題小記http://www.tkk7.com/xiaosilent/archive/2008/04/21/194559.htmlxiaosilentxiaosilentMon, 21 Apr 2008 09:38:00 GMThttp://www.tkk7.com/xiaosilent/archive/2008/04/21/194559.htmlhttp://www.tkk7.com/xiaosilent/comments/194559.htmlhttp://www.tkk7.com/xiaosilent/archive/2008/04/21/194559.html#Feedback0http://www.tkk7.com/xiaosilent/comments/commentRss/194559.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/194559.html閱讀全文

xiaosilent 2008-04-21 17:38 發表評論
]]>
在Ubuntu安裝Subversionhttp://www.tkk7.com/xiaosilent/archive/2008/04/12/192308.htmlxiaosilentxiaosilentFri, 11 Apr 2008 23:19:00 GMThttp://www.tkk7.com/xiaosilent/archive/2008/04/12/192308.htmlhttp://www.tkk7.com/xiaosilent/comments/192308.htmlhttp://www.tkk7.com/xiaosilent/archive/2008/04/12/192308.html#Feedback0http://www.tkk7.com/xiaosilent/comments/commentRss/192308.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/192308.html閱讀全文

xiaosilent 2008-04-12 07:19 發表評論
]]>
Eclipse導出JavaDoc中文亂碼問題解決http://www.tkk7.com/xiaosilent/archive/2007/11/28/163646.htmlxiaosilentxiaosilentWed, 28 Nov 2007 03:20:00 GMThttp://www.tkk7.com/xiaosilent/archive/2007/11/28/163646.htmlhttp://www.tkk7.com/xiaosilent/comments/163646.htmlhttp://www.tkk7.com/xiaosilent/archive/2007/11/28/163646.html#Feedback0http://www.tkk7.com/xiaosilent/comments/commentRss/163646.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/163646.html給 javadoc.exe 加上編碼參數就OK。

具體的:

在Eclipse里 export 選 JavaDoc,在向導的最后一頁的Extra JavaDoc Options 里填上參數即可

比如項目采用的是UTF-8的編碼就填:-encoding UTF-8 -charset UTF-8

o_javadoc.JPG



xiaosilent 2007-11-28 11:20 發表評論
]]>
響叮當 醫藥管理系統http://www.tkk7.com/xiaosilent/archive/2007/08/10/135922.htmlxiaosilentxiaosilentFri, 10 Aug 2007 11:30:00 GMThttp://www.tkk7.com/xiaosilent/archive/2007/08/10/135922.htmlhttp://www.tkk7.com/xiaosilent/comments/135922.htmlhttp://www.tkk7.com/xiaosilent/archive/2007/08/10/135922.html#Feedback0http://www.tkk7.com/xiaosilent/comments/commentRss/135922.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/135922.html閱讀全文

xiaosilent 2007-08-10 19:30 發表評論
]]>
修改 dTree , 實現節點的動態添加http://www.tkk7.com/xiaosilent/archive/2007/04/28/114394.htmlxiaosilentxiaosilentSat, 28 Apr 2007 08:54:00 GMThttp://www.tkk7.com/xiaosilent/archive/2007/04/28/114394.htmlhttp://www.tkk7.com/xiaosilent/comments/114394.htmlhttp://www.tkk7.com/xiaosilent/archive/2007/04/28/114394.html#Feedback8http://www.tkk7.com/xiaosilent/comments/commentRss/114394.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/114394.html閱讀全文

xiaosilent 2007-04-28 16:54 發表評論
]]>
MySQL和Java交互的中文亂碼http://www.tkk7.com/xiaosilent/archive/2007/01/17/94496.htmlxiaosilentxiaosilentWed, 17 Jan 2007 12:55:00 GMThttp://www.tkk7.com/xiaosilent/archive/2007/01/17/94496.htmlhttp://www.tkk7.com/xiaosilent/comments/94496.htmlhttp://www.tkk7.com/xiaosilent/archive/2007/01/17/94496.html#Feedback0http://www.tkk7.com/xiaosilent/comments/commentRss/94496.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/94496.html數據庫的亂碼問題,一直都相當惱人,不過,要解決起來,其實也還是比較容易……

首先,需要設定數據庫的編碼,也就是要在數據庫連接字串里面設置好編碼:
url=jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8
在建立數據庫連接的時候,再指定用戶名和密碼就可以了。

隨后,需要在數據庫和數據表里都設定好編碼:
CREATE DATABASE `db` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `db`;

CREATE TABLE `user` (
? `id` int(11) NOT NULL auto_increment,
?? `username` char(20) default NULL COMMENT '用戶名',
?? `password` char(20) default NULL COMMENT '密碼',
? PRIMARY KEY? (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;



最后是設定JSP文件的編碼,
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");

或者是用個Filter:

import ?java.io.IOException;

import ?javax.servlet.Filter;
import ?javax.servlet.FilterChain;
import ?javax.servlet.FilterConfig;
import ?javax.servlet.ServletException;
import ?javax.servlet.ServletRequest;
import ?javax.servlet.ServletResponse;

/**
?*?字符編碼過濾器
?*?
?*?
@author ?xiaosilent.
?*?
?
*/
public ? class ?CharacterEncodingFilter? implements ?Filter?{

????
protected ?FilterConfig?filterConfig;

????
private ?String?targetEncoding? = ? " UTF-8 " ;

????
/**
?????*?初始化過濾器,獲取初始化參數,如果沒有設定則使用默認的UTF-8編碼.
?????
*/
????
public ? void ?init(FilterConfig?config)? throws ?ServletException?{

????????
this .filterConfig? = ?config;

????????
// ?如果在web.xml里定義了編碼,則獲取,否則使用默認的UTF-8.
???????? if ?(config.getInitParameter( " encoding " )? != ? null )?{

????????????
this .targetEncoding? = ?config.getInitParameter( " encoding " );
????????}

????}

????
public ? void ?doFilter(ServletRequest?request,?ServletResponse?response,
????????????FilterChain?chain)?
throws ?IOException,?ServletException?{

????????request.setCharacterEncoding(targetEncoding);
????????response.setCharacterEncoding(targetEncoding);

????????chain.doFilter(request,?response);

????}

????
public ? void ?destroy()?{

????????filterConfig?
= ? null ;

????}

}
在web.xml里加入:? <filter>
? ?? ?<filter-name>CharacterEncodingFilter</filter-name>
? ?? ?<filter-class>xiao.cms.filter.CharacterEncodingFilter</filter-class>
? </filter>
? <filter-mapping>
? ?? ?<filter-name>CharacterEncodingFilter</filter-name>
? ?? ?<url-pattern>/*</url-pattern>
? </filter-mapping>
這里使用的是UTF-8,所以沒有指定參數,如果用非UTF-8編碼,指定一個名為encoding的參數即可.


經過這樣三個步驟,就不存在亂碼問題了。

另,不推薦用 MySQL-Front 這個客戶端程序管理UTF-8編碼的數據庫。如果是GBK編碼還可以考慮,UTF-8則會出現編碼問題,導致程序不能正常工作,強烈推薦 Navicat 。 功能強大,默認使用UTF-8編碼,界面友好、美觀。



xiaosilent 2007-01-17 20:55 發表評論
]]>
Properties讀取任意目錄的配置文件http://www.tkk7.com/xiaosilent/archive/2006/12/22/89575.htmlxiaosilentxiaosilentFri, 22 Dec 2006 10:50:00 GMThttp://www.tkk7.com/xiaosilent/archive/2006/12/22/89575.htmlhttp://www.tkk7.com/xiaosilent/comments/89575.htmlhttp://www.tkk7.com/xiaosilent/archive/2006/12/22/89575.html#Feedback4http://www.tkk7.com/xiaosilent/comments/commentRss/89575.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/89575.html然而,一般,我喜歡把web的配置文件放到WEB-INF里,和web.xml 文件放在一起,如果用getResourcesAsStream()肯定是不行了。
仔細想了一下,找到一個變通的方法:
????????try{
????????????
????????????String?url?
=?this.getClass().getResource("").getPath().replaceAll("%20",?"?");
????????????String?path?
=?url.substring(0,?url.indexOf("WEB-INF"))?+?"WEB-INF/config.properties";
????????????Properties?config?
=?new?Properties();
??????????? config.load(new FileInputStream(path));

????????????System.out.println(config.getProperty(
"dbDriver"));
????????}
????????
catch(Exception?e){
????????????e.printStackTrace();
????????}

這樣,就可以把配置文件放到任意位置了~~~~


xiaosilent 2006-12-22 18:50 發表評論
]]>
Ubuntu/Debian 下 Java中文支持問題http://www.tkk7.com/xiaosilent/archive/2006/12/10/86658.htmlxiaosilentxiaosilentSun, 10 Dec 2006 03:57:00 GMThttp://www.tkk7.com/xiaosilent/archive/2006/12/10/86658.htmlhttp://www.tkk7.com/xiaosilent/comments/86658.htmlhttp://www.tkk7.com/xiaosilent/archive/2006/12/10/86658.html#Feedback0http://www.tkk7.com/xiaosilent/comments/commentRss/86658.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/86658.html雖然在 wiki.ubuntu.org.cn 上的快速設置指南里有提到 java中文問題的解決辦法,但是,于我來說,我只需要能夠顯示中文就可以了,就不需要搞得那么復雜了。
還是在論壇里搜索了一下,找到一個相對來說,估計是最簡單的解決方法了。

cd?JAVA_HOME/jre/lib/fonts
sudo?mkdir?fallback
sudo?ln?-s?/usr/share/fonts/zh_CN/simsun.ttc?.
sudo?mkfontdir
sudo?mkfontscale

其中,JAVA_HOME代表的是jdk的安裝目錄,我是自己編譯安裝的sun的jdk,安裝目錄就是/usr/lib/j2sdk1.5-sun。 /usr/share/fonts/zh_CN/simsun.ttc 是我的宋體文件存放路徑,根據實際情況修改就是了。 只是,要注意的是,所使用的字體文件一定是要能夠支持中文的字體,否則,這一切都是白搭。


xiaosilent 2006-12-10 11:57 發表評論
]]>
Ubuntu下如何快速搭建JSF平臺http://www.tkk7.com/xiaosilent/archive/2006/11/15/build_a_JSF_develop_environment_on_Ubuntu.htmlxiaosilentxiaosilentWed, 15 Nov 2006 09:20:00 GMThttp://www.tkk7.com/xiaosilent/archive/2006/11/15/build_a_JSF_develop_environment_on_Ubuntu.htmlhttp://www.tkk7.com/xiaosilent/comments/81327.htmlhttp://www.tkk7.com/xiaosilent/archive/2006/11/15/build_a_JSF_develop_environment_on_Ubuntu.html#Feedback0http://www.tkk7.com/xiaosilent/comments/commentRss/81327.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/81327.html
在這里,我們使用自己編譯sun的J2SDK安裝包的方式進行安裝。
從sun下載最新的J2SDK安裝包,因為,是Ubuntu操作系統,所以,要選擇linux平臺下的jdk安裝包進行下載,得到文件jdk-1_5_0_06-linux-i586.bin。現在可以直接給.bin文件加上可執行權限,然后在終端下運行安裝程序,這里,我們要把它編譯成.deb包的形式再來安裝。
sudo?apt-get?install?java-package?java-common?fakeroot?
安裝上編譯需要的三個包。然后在終端下執行
fakeroot?make-jpkg?jdk-1_5_0_06-linux-i586.bin
,就會在當前目錄下生成一個名為sun-j2sdk1.5_1.5.0+update06_i386.deb的文件。這就是已經編譯好的jdk包了,然后是安裝,執行
sudo?dpkg?-i?sun-j2sdk1.5_1.5.0+update06_i386.deb
就可以安裝了(當然也可以直接雙擊.deb文件進行安裝)。 現在雖然安裝好了jdk,但是系統并沒有把jdk當成是默認的java解釋器(可以在終端執行 java -version 看看,是不是剛才安裝的 sun-j2sdk1.5_1.5.0),我們還需要執行
sudo?update-alternatives?--config?java
? 在彈出的選單中選擇帶有 sun 字樣的一項,就把新安裝的jdk設置成了默認的java解釋器。 現在再執行
java?-version
看看效果?最后,為了能夠正常運行 Apache Tomcat ,還需要設置一個 JAVA_HOME 變量。?
sudo?gedit?/etc/profile
? 在最后,加入?
export?JAVA_HOME=/usr/lib/j2sdk1.5-sun
(也許你的機器上的jdk的安裝路徑不是這樣的,你可以在新立得里查看jdk的屬性,確定其具體位置)。到這里,jdk的安裝算是安成了。
要指出的是,也許,源里面已經有jdk的包了,可以直接用源里的包安裝,但是,源里的包一般都不是最新的。而通過自己編譯的方式可以得到最新的jdk。


第二步就是安裝JDK了。

從www.eclipse.org上下載gtk版的eclipse3.2 (其實,只要你在ubuntu系統上用瀏覽器訪問,網站會自動把eclipse的版本和你系統想匹配) 解壓到本地的任意目錄就算是安裝完成了,簡單吧?


第三步就是安裝MyEclipse插件.

從 www.myeclipseide.com 下載 5.* 版的myeclipse 的 手動安裝包(ManualInstall),要注意的是,雖然網站上提供得有rpm格式的安裝包,這是給RedHat操作系統用的,Ubuntu是采用的Debian的deb格式封裝軟件包。把得到的zip文件解壓到本地的任意目錄,然后啟動eclipse,選擇 Help - Software Updates - Manage Configuration。在彈出的頁面中,可以看到 Eclipse SDK 下是eclipse的安裝路徑,在該路徑上點右鍵,在彈出的菜單中選擇 Add - Extension Locaion ,添加一個擴展,也就是要指定myeclipse的路徑了,在彈出的文件選擇對話框中,選擇myeclipse的路徑,確定就可以了。然后,根據提示重啟eclipse,myeclipse就算是安裝完成了。
最后是安裝Tomcat,從 tomcat.apache.org 下載非windows版本的安裝包,解壓到本地任意目錄,進入到$Tomcat_Home/bin,執行
./startup.sh?
就可以啟動 tomcat了,從終端的輸出信息我們還可以再次確認tomcat所使用的java解釋器是不是我們才安裝的jdk 打開瀏覽器,訪問 localhost:8080 查看到Tomcat的默認頁面。要停止tomcat,執行
./shutdown.sh
? 至于管理員帳戶的添加,可以根據tomcat默認頁面上的說明修改 $Tomcat_Home/conf 下的 tomcat-users.xml 文件,添加一個用戶,并把規則設置成 manager 就可以了。修改默認的 8080 端口,可以修改相同目錄下的 server.xml ,要注意的一點是,如果端口號小于1024,在啟動tomcat時,需要root權限,也就是用
sudo?./startup.sh
來啟動。

最后,還需要在MyEcipse里配置一下服務器,在 eclipse 的菜單欄上選擇 window - Preferences 展開 MyEclipse,展開 Application Servers ,選擇 Tomcat 5,在右側的編輯區中,先選擇 Enable,然后指定tomcat的根目錄(Tomcat Home Directory),根據實際情況指定即可。再在左側去展開 Tomcat 5, 查看JDK項,是不是剛才安裝的jdk。最后確認。這下回到eclipse的圖形工具欄,就可以通過 服務器 那個圖標啟動/重啟/關閉 tomcat。 點擊試試,彈出個菜單,里面有個Tomcat 5 子菜單吧,再選擇啟動,就可以在下面的 控制臺 看到一些輸出信息,并啟動tomcat。


xiaosilent 2006-11-15 17:20 發表評論
]]>
如何用Eclipse+MyEclipse快速搭建JSF開發環境http://www.tkk7.com/xiaosilent/archive/2006/10/10/74298.htmlxiaosilentxiaosilentTue, 10 Oct 2006 07:08:00 GMThttp://www.tkk7.com/xiaosilent/archive/2006/10/10/74298.htmlhttp://www.tkk7.com/xiaosilent/comments/74298.htmlhttp://www.tkk7.com/xiaosilent/archive/2006/10/10/74298.html#Feedback5http://www.tkk7.com/xiaosilent/comments/commentRss/74298.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/74298.html第一步:安裝Java環境
從sun官方下載J2SDK的安裝包,注意自己的系統平臺,不要下錯了。Ubuntu等Debian衍生系統可以直接apt-get安裝,安裝完成后,運行 sudo update-alternatives --config java 來完成默認java解釋器的配置,在出現的選項中選擇帶有sun-jdk5等類似字樣的選項即可。windows系列操作系統(估計沒有人再用win9x來寫Java應用了)直接執行下載回來的可執行文件,可以選擇不安裝獨立的jre和演示程序源碼包等,記下安裝的路徑。安裝完成后,在桌面(Desktop)上右擊 我的電腦(My Computer)圖標,選擇 屬性(Properties) 選擇 高級(Advanced)選項卡,選擇環境變量(Environment variables...) 選擇 新建(New...)(任意一個新建都可以,建議選擇修改當前用戶的環境變量).在變量名中填寫"PATH"(引號不用寫),變量值處填寫".;d:\Jdk\bin"(假設,剛才的安裝路徑為d:\Java,根據自己實際情況進行修改)。再確定退出就可以了。可以在命令行里面驗證一下,看是否配置正確:win+R鍵,打開運行(Run...)對話框,輸入command,運行 java -version? 看是否有 相關的輸出。如果沒有仔細檢查剛才環境變量的設置。
第二步:安裝Eclipse
說是安裝Eclipse,就是去Eclipse官方下載自己相應版本的Eclipse的壓縮包,解壓到自己喜歡的目錄就可以了。windows平臺,直接執行eclipse.exe就可以了,Linux平臺下可以先在桌面/面板等地方建立一個到解壓出目錄下的eclipse文件的連接,在執行該鏈接就可以了,也可以在終端里面執行。要說明的是,必須要先正確執行第一步才可以成功運行Eclipse。
第三步:安裝MyEclipse插件
從MyEclipse官方下載和自己Eclipse版本和自己系統平臺相對應的版本的MyEclipse插件安裝包,下載回來后執行該安裝文件(這里,各個平臺的安裝方式都一樣,只是啟動安裝程序的方式不同而已),指定先前安裝的Eclipse的路徑和要把MyEclipse安裝到的路徑,直接安裝完成即可。
第四步:安裝Jsp/Servlet容器
以安裝Tomcat為例,從Tomcat官方下載自己對應平臺的安裝包。windows平臺就不再說了,Linux平臺下載回來的是壓縮包,解壓到適當目錄,并,修改/etc/profile或其他環境變量配置文件。在文件后添加?
export JAVA_HOME=yourPath
export TOMCAT_HOME=yourPath
這兩行,把其中的yourPath替換成你實際的路徑就是了。然后重新啟動計算機使更改生效(也可以通過在終端里執行 source /etc/profile 的方式來即時更新環境變量,但是后面所有的操作,都必須在該終端下進行。)。
下面就是如何建立JSF工程了。
啟動Eclipse 設置缺省的工作區位置,關掉Welcome窗口,出現缺省的JDT視圖。選擇 File-New-Project-MyEclipse-J2EE Projects-Web Project,打開 New J2EE Web Project 對話框,填寫適當的工程名等信息,一定要認真填寫 Context root URL 這將會是你發布工程時的工程名。確定,系統提示要打開 MyEclipse J2EE Development 視圖,選擇 Yes 就自動打開該視圖。這樣,在左邊的Package Explorer 看將會看到剛才建立的工程,且該工程的根目錄被選定,現在在菜單欄上選擇 MyEclipse-Add JSF Capabilities。打開 JavaServer Faces Support for MyEclipse Web Project 對話框,選擇適當的 JSF 實現(JSF Implementation),等等其他相關信息。再單擊 Finish 就可以了。 這樣,一個 JSF 工程就建好了,可以進行開發了。
最后,是發布工程。在發布工程以前,我們需要配置一下服務器。找到圖形工具欄上的 啟動服務器 的圖標,選擇 Configure Server 在出現的對話框中展開左邊的Application Servers 樹,找到 Tomcat5 單擊,在右邊出現的配置區中,選擇 Enable 然后在 Tomcat Home Directory 中填寫自己的 Tomcat 的安裝路徑 確定就可以了。在圖形工具欄上剛才的服務器圖標的左邊,是發布工程的圖標,選擇,出現對話框。在 Project 后的選單里選擇剛才的工程,在 Deployments 中選擇 Add 出現 New Deployment 對話框,在Server里選擇剛才配置好的Tomcat5,然后是選擇是要發布成打包的.war 文件(Packaged Archive)還是直接按目錄發布(Exploded Archive)。確認就是了。然后啟動Tomcat,就可以看到自己剛建立的工程了。

xiaosilent 2006-10-10 15:08 發表評論
]]>
[譯] JavaServer Faces in Action 中關于 action listener 的講解部分http://www.tkk7.com/xiaosilent/archive/2006/10/10/74283.htmlxiaosilentxiaosilentTue, 10 Oct 2006 05:44:00 GMThttp://www.tkk7.com/xiaosilent/archive/2006/10/10/74283.htmlhttp://www.tkk7.com/xiaosilent/comments/74283.htmlhttp://www.tkk7.com/xiaosilent/archive/2006/10/10/74283.html#Feedback2http://www.tkk7.com/xiaosilent/comments/commentRss/74283.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/74283.html第一次嘗試翻譯,難免錯誤百出,敬請指正。

當用戶和代表命令或某操作(gesture)等控件發生交互的時候,觸發 動作事件(action event)。產生動作事件的組件也叫做動作源,包括了按鈕、超鏈接等組件。動作事件由動作監聽器(action listener)進行處理。

有兩種典型的監聽器:一種會影響到頁面間的導航(navigation),另一種不會影響到導航。影響到頁面間導航的監聽器主要是處理一些業務邏輯并返回幾個業務邏輯結果,JSF的導航系統將會根據這個來選擇恰當的下一個頁面(譯注:并非傳統所說的TRUE/FALSE這兩種“邏輯”結果,這里講的是“業務邏輯”,可以是任意的有代表意義的結果。)不影響導航的事件監聽器用來操作當前頁面內的組件,或者是進行一些業務模型上的改變,或者是修改backing bean的屬性等,并不會出現在頁面間的跳轉。

在技術上,所有頁面間導航都是由一個單一的動作監聽器來處理。這個監聽器自動處理組件所觸發的所有事件(event),因此,該監聽器并不需要手動地注冊/綁定(register)。缺省情況下,這個監聽器會將所有的工作交由你制定的backing bean中的某個方法(method)來處理。因此,你可以用不同的方法來處理你程序中的各個業務部分。典型地,你的大多數業務邏輯都將會交由這些方法來處理。

當某個組件觸發一個事件的時候,缺省的監聽器就決定了該事件的處理結果,該結果用一個字符串(string)來表示,比方說:"success"、"failure" 等。這個結果也可以分為靜態和動態兩類。靜態的是在編碼的時候就已經定義好了的例如:
<h:commandButton type="submit" value="Login" action="success" immadiate="true" />
在這個例子當中,當用戶點擊這個標為Login的按鈕的時候,會產生 "success" 這個業務結果并同時觸發該按鈕被點擊這個事件,但是,并沒有相應的方法來處理這個事件。

而動態的結果就是由處理該事件的方法所返回的,一個字符串。一個方法可能會返回多個不同的結果,這取決于業務邏輯。動作監聽器會自動查找你在該組件的 action 屬性中指定的方法,并執行。我們用 EL(expression language) 來指定該屬性值。下面是一個 HtmlCommandButton 的實際例子:
<h:commandButton type="submit" value="Login" action="#{user.login}" />
當用戶點擊該按鈕,一個代表該按鈕被點擊的事件產生,并執行下面的事件處理方法:

?1 public ? class ?User {
?2
?3 ?? public ?String?login() {
?4 ???? if () {? // 登陸成功
?5 ?????? return ? " success " ;
?6 ????}
else {? // 登陸失敗
?7 ?????? return ? " failure " ;?
?8 ????}

?9 ??}

10
11 }

login方法的返回值取決于不同的業務邏輯,這里暫不討論。類User 是一個 backing bean 它的某些屬性值和頁面上的某些輸入控件的值相關聯。 而該類會在 faces-config.xml 中有相應的定義。

上面的例子中僅有 "success"、"failure" 等返回值,但是,實際應用中,你的程序可能要求你能操縱JSF組件、業務模型對象、添加消息等等。甚至是 實現頁面的直接跳轉、輸出某個適當響應、和數據庫 EJB 等組件 服務等實現交互 等等復雜的功能。動作監聽器根據方法的返回值和導航系統中的定義來決定頁面跳轉。

當你需要執行業務邏輯又不需要頁面的跳轉的時候,你可以給組件綁定一個 動作監聽器方法(action listener method),有別于動作方法(action method),該方法除了可以綁定事件,還可以操縱組件。我們看下面的例子:
<h:commandButton id="redisplayButton" type="submit" value="Redisplay" actionListener="#{loginForm.doIt()}" />
和前面的例子一樣,當用戶點擊該按鈕,有事件產生。但是,這次,動作監聽器方法得到執行,而不是先前的動作方法。

1 public ? void ?doIt(ActionEvent?event) {
2 ??HtmlCommandButton?button? = ?(HtmlCommandButton)event.getComponent();
3 ??button.setValue( " Try?again! " );
4 }

該方法會改變先前點擊的按鈕的標題,雖然這并沒有多少用處。但重要的是,這個方法的簽名。他接受了一個 ActionEvent 類的參數,并沒有返回值。這,就是 action listener method 和 action method 的主要區別!在前面的方法執行完以后,頁面會被刷新,以顯示效果。

通常,用 action listener method 方法來執行對當前頁面的改變。比方說 value-changing 事件等,你也可以用一個接口來實現,然而,在大多數情況下,用 backing bean 中的方法來實現就已經足夠了。



xiaosilent 2006-10-10 13:44 發表評論
]]>
JavaServer Faces in Action中 關于 action listener 的講解http://www.tkk7.com/xiaosilent/archive/2006/10/10/74259.htmlxiaosilentxiaosilentTue, 10 Oct 2006 03:58:00 GMThttp://www.tkk7.com/xiaosilent/archive/2006/10/10/74259.htmlhttp://www.tkk7.com/xiaosilent/comments/74259.htmlhttp://www.tkk7.com/xiaosilent/archive/2006/10/10/74259.html#Feedback0http://www.tkk7.com/xiaosilent/comments/commentRss/74259.htmlhttp://www.tkk7.com/xiaosilent/services/trackbacks/74259.html 稍后奉上翻譯__==__
Action events are triggered when a user interacts with a control that represents a command,or a user gesture. Components that generate action events,also called action sources,include controls such as buttons or hyperlinks.Action events are handled by action listeners.

There are two types of action listeners:those that affect navigation,and those that don't.Action listeners that affect navigation typically perform some processing and then return a logical outcome that is used by JSF's navigation system to select the next page(which may actually be the same page that's currently being viewed). Listeners that don't affect navigation usually manipulate components in the current view,or perform some processing that changes model object or backing bean properties,but doesn't alter the current page the user is accessing.

Technically,all navigation is handled by a single action listener.This listener automaatically handles any action events fired by a component,so it doesn't need to be registered manually.By default,this action listener delegates all of its work to action methods in your backing beans,so you can have different action methods handle different parts of your application.Typically,most of your application logic will be located in these methods.(The action listener is pluggable,so it's possible to replace it with one that doesn't use action methods at all.)

When a component fires an action event,this default action listener determines its outcome string---"success"or"failure",for example.There are two basic types of outcomes:static and dynamic.Static outcomes are hardcoded string that are declared with the component or set in code:
<h:commondButton type="submit" value="Login" action="success" immediate="true"/>
In this example,the static outcome of "success" will be generated when the user clicks on this HtmlCommandButton and generates an action event--no
action method will be called.

Dynamic outcomes are strings returned by action methods themselves---an action method might return a different outcome depending on whateever application logic it performs.The action listener looks for an action method whenever you use a JSF EL(Expression Language) expression in the action property.Here's an HtmlCommandButton that exectutes an action method instead:
<h:commandButton type="submit" value="Login" action="#{user.login}"/>
When a user clicks on this button,an action event is fired,and the follwing method is executed in response to the event:

?1 public ? class ?User {
?2
?3 ?? public ?String?login() {
?4 ???? if () {? // ?successfully?login
?5 ?????? return ? " success " ;
?6 ????}
else {
?7 ?????? return ? " failure " ;
?8 ????}

?9 ??}

10
11 }


Based on some voodoo application logic,this action method returns an outcome of either "success" or "failure" . User is a backing bean whose properties are wired up to input control values on the page,and is configured via the Managed Bean Creation facility.

My example has voodoo logic,but your action methods can manipulate JSF components,model objects,or add messages.They can also do other fun tasks,such sa performing a redirect,rendering a response(a graphic or some binary type of data),ading events,and talking to databases,EJB(Enterprise JavaBean) servers,or web services.The action listener uses the outcome of an action method to hook into the navigation system and determine what page to choose next.

When you need to execute application logic that is not associated with navigation you can associate an action listener method with a component.Unlike action methods,action listener methods have access to the component that fired the event as well.Take a look at this example:
<h:commandButton id="redisplayCommand" type="submit" value="Redisplay" actionListener="#{myForm.doIt}" />
Like the previous example , when a user clicks on this HtmlCommandButton , an action event is fired. This time,however,the action listener method is
executed instead of the action method:

1 public ? void ?doIt(ActionEvent?event) {
2 ??HtmlCommandButton?button? = ?(HtmlCommandButton)event.getCommponent();
3 ??button.setValue(? " It's?done! " ?);
4 }

5

This method changes the value(label) of the button that fired the event---not terribly useful.What's important,however,is its method signature.Instead of accepting an ActionEvent sa a parameter and don't return an outcome at all. After this method executes,the page will be redisplayed,incorporating any changes made by the method.

Usually,you use action listener methods for changes that affect the current view. Like value-change listeners,you can also implement an action listener using a Java interface,although in most cases using a method in an existing backing bean is sufficient.



xiaosilent 2006-10-10 11:58 發表評論
]]>
主站蜘蛛池模板: 亚洲日韩欧洲无码av夜夜摸| 亚洲Av无码一区二区二三区| 3344免费播放观看视频| 一区二区亚洲精品精华液| www国产亚洲精品久久久| 美女视频黄的免费视频网页| 亚洲综合一区无码精品| 亚洲一区二区三区偷拍女厕| 麻豆最新国产剧情AV原创免费| 色多多A级毛片免费看| 亚洲系列国产精品制服丝袜第| 国产乱人免费视频| 99久久综合精品免费| 午夜在线亚洲男人午在线| 亚洲第一成年人网站| 亚洲色婷婷综合开心网| 国产又黄又爽又猛免费app| 国产免费久久精品丫丫| 亚洲欧美日韩国产成人| 色播亚洲视频在线观看| 亚洲免费一区二区| 午夜时刻免费入口| 2022久久国产精品免费热麻豆| 一级毛片aaaaaa视频免费看| 91在线亚洲综合在线| 亚洲综合无码一区二区| 亚洲中文字幕无码爆乳AV| 日韩免费观看视频| 久久久高清免费视频| 性xxxxx大片免费视频| 爱情岛论坛亚洲品质自拍视频网站 | 老司机69精品成免费视频| 猫咪免费人成在线网站| 国产亚洲精品bv在线观看| 亚洲综合精品一二三区在线 | 亚洲一级高清在线中文字幕| 亚洲精品国产精品乱码在线观看| 国产成人免费手机在线观看视频 | 亚洲人成网站在线在线观看| 亚洲精品成人图区| 无码乱人伦一区二区亚洲一|