Meet Apache Wicket

剛開始接觸Wicket,所以很多內容都是直譯,把原文貼上,望大家指正


Meet Apache Wicket

    By JonathanLocke, original author of Wicket

    喬納森·洛克,Wicket的原作者

Why Wicket?

 

    If you arelooking to do web application programming in Java, you have a very large numberof choices these days. In fact, there are so many web application frameworksnow that it has become somewhat of a joke. One blog site on the Internet posesthe question: How many Java web frameworks can you name? The answer they showlooks like this:

    如果你打算做 Web應用程序的編程用java,如今你有非常多的選擇。事實上,有這麼多的Web應用程序框架現在它已經變得多少有點可笑了。一個網上的博客裏提出了一個問題:有多少的JavaWeb框架你可以說出來?他們的答案是這樣的:

Frameworks, Frameworks Everywhere

Echo

Cocoon

Millstone

OXF

Struts

SOFIA

Tapestry

WebWork

RIFE

Spring MVC

Canyamo

Maverick

JPublish

JATO

Folium

Jucas

Verge

Niggle

Bishop

Barracuda

Action Framework

Shocks

TeaServlet

wingS

Expresso

Bento

jStatemachine

jZonic

OpenEmcee

Turbine

Scope

Warfare

JWAA

Jaffa

Jacquard

Macaw

Smile

MyFaces

Chiba

JBanana

Jeenius

JWarp

Genie

Melati

Dovetail

Cameleon

JFormular

Xoplon

Japple

Helma

Dinamica

WebOnSwing

Nacho

Cassandra

Baritus

Stripes

Click

GWT

 

 


Why Reinvent the Wheel?

    爲什麼要“推倒重來”

    In light ofthis, you may be wondering What good isanother web application framework? Indeed. Why re-invent the wheel? One snappy comeback to that old saw is: because this time we couldmake it rounder!

    But it was notsimply a desire for higher quality that drove the creation of Wicket. Even withso many options, there really is no web toolkit which fills exactly the nichethat Wicket fills. In fact, Wicket is quite unlike each of the frameworksabove.

Wickets closest cousins are probably Tapestry andEcho, but even there the likeness is very shallow. Like Tapestry, Wicket uses aspecial HTML attribute to denote components, enabling easy editing withordinary HTML editors. Like Echo, Wicket has a first-class component model. ButWicket applications are not like applications written in either Tapestry orEcho, because in Wicket you get the best of both worlds. You get the benefitsof a first-class component model and a non-intrusive approach to HTML. In manysituations, this combination may prove to be a significant developmentadvantage.

    To understandwhy Wicket is so different, it may help to understand the motivations thatcreated it.

    鑑於這一點,你可能會想“另一種Web應用框架有什麼好處呢?”的確如此。爲什麼要“推到重來呢?”這讓我想起來一個老話:因爲我們可以做的更完美!

    但它爲更高質量的實現並不是創造wicket的唯一動機。即使有這麼多的選擇,但是並沒有一個web工具能完全符合wicket文件。事實上,Wicket的是完全不同於上述各框架。

    Wicket的最親密的表兄弟可能是Tapestry和Echo,但即使有想象的地方也是很少的。像Tapestry ,Wicket使用一種特殊的HTML屬性來表示的元件,可以方便編輯與普通的HTML編輯器。像Echo,Wicket擁有一流的組件模型。但Wicket的應用程序並不像寫在任的Tapestry或Echo的應用,因爲在Wicket裏你可以兩全其美。你可以同時在第一級的部件模型和非侵入式方法的HTML中的好處。在許多情況下,這種組合可能被證明有顯著發展優勢。

 

    要理解爲什麼Wicket的是如此的不同,它可能有助於瞭解創建它的動機。

 

Motivations

 Most existingweb frameworks provide weak to non-existent support in managing server-sidestate

大多數存在的web框架提供幾乎不存在的管理服務端狀態的支持

    This normallymeans lots of ad-hoc code in web applications dealing with the gory mechanicsof state management. While Wicket will not allow you to stop thinking aboutserver state, it goes a long ways towards making it easy and often transparentto manage that state.

   In Wicket, allserver side state is automatically managed. You will never directly use anHttpSession object or similar wrapper to store state. Instead, state isassociated with components. Each server-side page component holds a nestedhierarchy of stateful components, where each components model is, in the end, a POJO (Plain OldJava Object). Wicket maintains a map of these pages in each users session. One purpose of this page map(and the component hierarchy on each page) is to allow the framework to hideall details of how your components and models are accessed. You deal withsimple, familiar Java objects and Wicket deals with things like URLs, sessionids and GET/POST requests.

    通常,這意味着大量的專門的代碼在Web應用程序處理狀態管理。而Wicket不會讓你停止關於服務器狀態的思考,他在朝着使用更容易更透明化管理的方向上經過了一個漫長的道路。

    在Wicket中,所有的服務器端的狀態會自動進行管理。你將永遠不會直接使用HttpSession對象或類似的包裝器來存儲狀態。相反,狀態與組件相關聯。每個服務器端頁面組件保存有一個嵌套層次的有狀態組件,每個組件的模型的最後是一個POJO(普通的Java對象)。Wicket包含這些頁面的地圖中每個用戶的會話。這個頁的映射(每個頁面上的組件層次結構)的目的之一是讓框架隱藏瞭如何將組件和模型訪問的所有細節。你只需要處理簡單、熟悉的Java對象,Wicket處理的事情,比如URLs,session ID和GET/POST請求。

 

    You will alsofind that this well-structured server state makes it very easy to deal with thedreaded back buttonproblem. In fact,Wicket has a generic and robust solution which can identify and expirebrowser-cached pages that have become stale due to structural changes to themodel of a component on the page.

    Finally, Wickethas been designed to work with POJO persistence frameworks such as JDO orHibernate. This can make database driven web applications quite easy to write.

    For manyapplications, it will be worth trading off the increased server load of extraserver-side state for decreased development costs, lower maintenance costs,quicker time-to-market and generally higher quality software. The basicobservation here is that software is expensive and complex while servers fromcompanies like E-machines and Dell are relatively dirt cheap.

    In terms ofefficiency versus productivity, perhaps Wicket is to JSP as Java is to C. Youcan accomplish anything in Wicket in JSP. You may even do it more efficientlyin terms of memory or processor consumption. But it may take you weeks ormonths longer to develop your application. And in the end, since state managementin JSP is ad-hoc, you are likely find security problems and bugs popping upeverywhere. Most of the other frameworks above will do only a little more tohelp you.

    你還會發現,這個結構良好的服務器狀態使得它很容易對付可怕的“後退按鈕的問題”。事實上,Wicket有一個通用的和強大的解決方案,它可以識別和過期的瀏覽器緩存頁面已經陳舊由於對頁面上的一個組件模型的結構變化。。

    最後,Wicket已被設計爲與POJO持久性框架如Hibernate或者JDO。這可以使數據庫驅動的Web應用程序更容易實現。

對於許多應用程序,這將是一筆值得的交易,去增加額外的服務器端狀態,降低開發成本,降低維修成本,縮短上市時間,實現更高質量的軟件。這裏的基本看法是,軟件是昂貴和複雜的e-machines和戴爾公司的服務器是相對便宜的。

    在效率與生產力方面,或許Wicket對於JSP的關係就想Java對於C一樣。您可以在Wicket中在JSP中完成任何事情。你甚至可以更有效地做到這一點的內存或處理器​​消耗方面。但它可能需要你幾個星期甚至幾個月更長的時間來開發應用程序。而在最後,因爲狀態管理在JSP是臨時的,你很可能發現的安全問題和錯誤遍地開花。最上面的其他框架對你的幫助只能是微乎其微。

 

 

Most existingframeworks require special HTML code

大多數現有的框架需要特殊的HTML代碼

    JSP is by farthe worst offender, allowing the embedding of Java code directly in web pages,but to some degree almost all of the frameworks from the list (except Tapestry)above introduce some kind of special syntax to your HTML code.

   JSP是迄今爲止最嚴重的錯誤,就是允許直接在網頁中的Java代碼嵌入,但在一定程度上幾乎所有的框架(除Tapestry)在列表上面介紹某種特殊的語法來你的HTML代碼。

 

   Special syntaxis highly undesirable because it changes the nature of HTML from the kind ofpure-and-simple HTML markup that web designers are familiar with, to some kindof special HTML. This special HTML can be more difficult to preview, edit andunderstand.

    特殊的語法是極不可取,因爲它把HTML自然純淨而簡單的那種網絡設計是特別熟悉的HTML標記,轉換成對一些特殊的HTML。這種特殊的HTML是更預覽編輯和理解的。

    Wicket does notintroduce any special syntax to HTML. Instead, it extends HTML in astandards-compliant way via a Wicket namespace that is fully compliant with theXHTML standard. This means that you can use Macromedia Dreamweaver, MicrosoftFront Page, Word, Adobe Go Live, or any other existing HTML editor to work onyour web pages and Wicket components. To accomplish this, Wicket consistentlyuses a single id attribute in the Wicket namespace (wicket:id) to mark HTMLtags that should receive special treatment by the toolkit. If you prefer not torender Wicket namespaced tags and attributes to your end-users, Wicket has asimple setting to strip them all out, resulting in ordinary,standards-compliant HTML.

    Wicket不引入任何特殊的語法爲HTML。相反,它通過是完全符合XHTML標準一個Wicket命名空間擴展的HTML標準兼容的方式。這意味着你可以使用Macromedia的Dreamweaver,Microsoft FrontPage, Word, Adobe Go Live,或任何其他現有的HTML編輯器工作在您的網頁和Wicket組件。要做到這一點,Wicket一貫使用的Wicket命名空間中的單個id屬性(“Wicket:ID”)來標記應接受特殊處理的工具包的HTML標籤。如果你不喜歡渲染Wicket命名空間的標籤和屬性到您的終端,Wicket有一個簡單的設置使我們都脫離他們,實現一個普通的,符合標準的HTML。

    No special sauce in your HTMLmeans designers can mock up pages that you can use directly in development.Adding Java components to the HTML is as simple as setting the component nameattribute. And you can then give the HTML back to your web designers knowingthat they can change it with confidence.

    沒有“調料”在你的HTML意味着設計師模擬的頁面,可以直接在程序中使用。添加Java組件到HTML想設置組件的名字屬性一樣簡單。然後把HTML返回到網頁設計師那裏並且讓他們知道改變網頁是一件很容易的事情。

 

    Wicket, more thanany other framework gives you a separation of concerns. Web designers can workon the HTML with very little knowledge of the application code (they cannotremove the component name tags and they cannot arbitrarily change the nestingof components, but anything else goes). Likewise, coders can work on the Javacomponents that attach to the HTML without concerning themselves with what agiven page looks like. By not stepping on each others toes, everyone can get more work done.

    Wicket,比其他任何框架更容易實現分層。網站設計者用很少的應用代碼的知識只是去操作HTML(他們無法刪除的組件名稱標籤,他們不能隨意更改組件,其他的都可以)。同樣,編碼器可以工作在Java組件連接到HTML不關心什麼一個給定的頁面。只要不踩其他人的腳趾頭,每個人都可以做更多的工作。

 

Existingframeworks are not easy

現有的框架都不是簡單的

    Most of theexisting toolkits have poorly defined or non-existent object models. In somecases, the model is defined using special XML syntaxes. The syntaxes may be socumbersome that special tools are required to manipulate all the configurationinformation. Since these toolkits are not simple Java libraries you may or maynot be able to use your favorite IDE tools such as editors, debuggers andcompilers.

    Wicket is allabout simplicity. There are no configuration files to learn in Wicket. Wicketis a simple class library with a consistent approach to component structure. InWicket, your web applications will more closely resemble a Swing applicationthan a JSP application. If you know Java (and especially if you know Swing),you already know a lot about Wicket.

    大多數現有的工具包都定義不清或不存在的對象模型。在某些情況下,該模型是使用特殊的XML語法來定義。該語法可能是這樣繁瑣的特殊工具來操作所有的配置信息。由於這些工具包是不是簡單的Java庫,你可能會或可能無法使用您喜歡的IDE工具,如編輯器,調試器和編譯器。

    Wicket是簡單並且有沒有配置文件。 Wicket的是一個簡單的類庫,用一致的方法來組成結構。在Wicket中,你的Web應用程序會更接近於比JSP應用程序Swing應用程序。如果你知道的Java(特別是如果你知道Swing),你已經知道了很多關於Wicket。

 

Existingframeworks inhibit reusability

現有的框架複用性不好

    Tapestry and JSFat least have component models that allow reuse, but you are likely to findthat it is not particularly trivial to do, at least when compared with Wicket.Wicket has been explicitly designed to make it very, very easy to createreusable components. Its surprisinglysimple to extend existing components and to make compound components such as aSignInPanel or AddressForm. It is also relatively easy to create componentsthat exploit new features of browsers. Components in Wicket can be packaged upin JAR files and reused by simply dropping them in your lib folder - noconfiguration necessary!

    Tapestry和JSF至少有組件模型,允許重用,但你很可能會發現,這是不是特別容易做到,至少在Wicket相比。Wicket已經被明確設計,使其非常、非常容易地創建可重用的組件。這是令人驚訝的簡單擴展現有的組件和使複合組件,如SignInPanel或爲AddressForm。它也是相對容易地創建利用瀏覽器的新功能部件。在Wicket組件可以被打包成JAR文件,並通過簡單的拖放在你的lib文件夾重複使用 - 無需進行必要的配置!

Web programmingshould be fun!

Web編程應該是樂趣無窮!

    This is my mostpersonal goal for writing Wicket . None of the existing frameworks areappealing to me in terms of intuitiveness, quickness, ease of development, etc.It is my hope that Wicket represents a significant step in the direction ofmaking web applications easy and fun to write.

    Web變成是有趣的——這是我寫的Wicket最個人的目標。現有的框架沒有一個能夠吸引我的眼球,我希望有一個可以進行直觀的,快速的,易於開發的框架,Wicket使Web應用程序更容易有有趣的去實現!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章