OSGi與JSF結(jié)合開(kāi)發(fā)
首先感謝羅明提供的無(wú)私幫助,很多天來(lái)一直沒(méi)有將OSGi的JSF應(yīng)用問(wèn)題解決,這兩天跟羅明在網(wǎng)上聊關(guān)于這方面的話題,給予了我不少的幫助,同時(shí)也使我的問(wèn)題得到了解決。
這些日子沒(méi)有少在羅明的博客上晃悠,但總是讓人感覺(jué)這個(gè)家伙總喜歡“高手過(guò)招,點(diǎn)到為止”,這樣可能對(duì)于大多數(shù)對(duì)OSGi接觸不多的人來(lái)說(shuō),可能還是有些抽象,為了方便大家學(xué)習(xí)和使用OSGi,我決定自己寫(xiě)一篇關(guān)于OSGi與JSF結(jié)合的例子,比較詳細(xì)的介紹如何實(shí)現(xiàn)一個(gè)OSGi與JSF結(jié)合的例子。
在OSGi與JSF結(jié)合的使用中,由于需要改寫(xiě)一些由Equinox實(shí)現(xiàn)好的項(xiàng)目org.eclipse.equinox.jsp.jasper的一些源碼,因此,操作起來(lái)似乎稍微要麻煩一些,Equinox上的項(xiàng)目基本上都是通過(guò)CVS來(lái)管理的,因此首先需要保證自己已經(jīng)安裝了CVS客戶端,然后拉下代碼,為下面的工作做好準(zhǔn)備。
先就將OSGI與JSF的結(jié)合使用例表如下:
1. 建立plugin工程:osgi.jsf.finals
2. 編寫(xiě)頁(yè)面
◆index.jsp
- <%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
- <%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
- <%@page contentType="text/html;charset=UTF-8"%>
- <html>
- <head>
- <title>JSF Samples</title>
- </head>
- <body>
- <f:view>
- <h:form>
- <h:outputText style="color:red" value="#{user.errMsg}" />
- <h3>JSF Samples</h3>
- Nick Name: <h:inputText value="#{user.id}"/><p>
- <h:commandButton value="Submit" action="#{user.verify}"/>
- </h:form>
- </f:view>
- </body>
- </html>
◆welcome.jsp
- <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
- <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
- <%@page contentType="text/html;charset=UTF-8"%>
- <html>
- <head>
- <title>JSF Samples</title>
- </head>
- <body>
- <f:view>
- <h:outputText value="#{user.id}"/> Welcome!
- <h3>JavaServer Faces!</h3>
- </f:view>
- </body>
- </html>
3. 實(shí)現(xiàn)相應(yīng)類(lèi)UserBean.java
- package org.danlley.jsf.beans;
- public class UserBean {
- private String id;
- private String pwd;
- private String errMsg;
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getErrMsg() {
- return errMsg;
- }
- public void setErrMsg(String errMsg) {
- this.errMsg = errMsg;
- }
- public String getPwd() {
- return pwd;
- }
- public void setPwd(String pwd) {
- this.pwd = pwd;
- }
- public String verify() {
- if (id.equals("jsfUser")) {
- return "success";
- } else {
- setErrMsg("userID should be jsfUser");
- return "failed";
- }
- }
- }
【編輯推薦】