第一次接触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.
Wicket’s 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 component’s model is, in the end, a POJO (Plain OldJava Object).
Wicket maintains a map of these pages in each user’s 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不会让你停止关于server状态的思考,他在朝着使用更easy更透明化管理的方向上经过了一个漫长的道路。
在Wicket中,全部的server端的状态会自己主动进行管理。你将永远不会直接使用HttpSession对象或类似的包装器来存储状态。相反。状态与组件相关联。每一个server端页面组件保存有一个嵌套层次的有状态组件。每一个组件的模型的最后是一个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.
你还会发现,这个结构良好的server状态使得它非常easy对付可怕的“后退button的问题”。其实,Wicket有一个通用的和强大的解决方式。它能够识别和过期的浏览器缓存页面已经陈旧因为对页面上的一个组件模型的结构变化。
。
最后,Wicket已被设计为与POJO持久性框架如Hibernate或者JDO。这能够使数据库驱动的Web应用程序更easy实现。
对于很多应用程序。这将是一笔值得的交易,去添加额外的server端状态,减少开发成本,减少维修成本。缩短上市时间,实现更高质量的软件。
这里的基本看法是,软件是昂贵和复杂的,像e-machines和戴尔公司的server是相对廉价的。
在效率与生产力方面,也许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返回到网页设计师那里而且让他们知道改变网页是一件非常easy的事情。
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 other’s toes, everyone can get more work done.
Wicket,比其它不论什么框架更easy实现分层。站点设计者用非常少的应用代码的知识仅仅是去操作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. It’s 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至少有组件模型,同意重用。但你很可能会发现,这是不是特别easy做到,至少在Wicket相比。Wicket已经被明白设计,使其很、很easy地创建可重用的组件。这是令人吃惊的简单扩展现有的组件和使复合组件。如SignInPanel或为AddressForm。
它也是相对easy地创建利用浏览器的新功能部件。在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应用程序的更多easy有感兴趣的实现!