如何创建自定义的Java Web控件? [英] How to create Java Custom Web Controls?

查看:210
本文介绍了如何创建自定义的Java Web控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是原初的在我的头上为我可以使用AWT控制在Servlet?后,它会显示我对这一问题的所有无知。

This question was originary in my head as "Can I use AWT controls in a Servlet?", which will show all my ignorance on the subject.

我是新来的Java技术,但一点阅读后,我似乎明白了AWT控制直接挂钩操作系统GUI元素,所以没有办法在Servlet使用或扩展JPanels,Jbutton将等被注入在JSP中,让浏览器渲染这些控件(另一种也许可以在JSP中嵌入一个applet,但我不想这样做)。

I am new to JAVA technologies but after a bit of reading, I seem to understand AWT controls directly hook up the OS GUI elements so there is no way to use or extend JPanels, JButtons and so forth in a Servlet to be injected in a JSP and let the browser render those controls (an alternative could probably be embedding an applet in a JSP but I don't wanna do that).

我找了构建基于JSP和Servlet定制的可重复使用的Web控件的方式。

I am looking for a way of building custom re-usable web controls using JSPs and Servlets.

这是怎么做的,通常,你可以提供一些样品/链接?

How is this usually done and can you provide some samples/links?

编辑:这是一个测试运行我给的谷歌应用程序引擎的一部分 - 所以它可能会有意义对我来说,探索谷歌Web工具包 - 这种方向的任何指针会AP preciated为好。

This is part of a test run I am giving to the Google Application Engine - so it would probably make sense for me to explore the Google Web Toolkit - any pointers in that directions would be appreciated as well.

任何帮助AP preciated!

Any help appreciated!

推荐答案

AWT 是UI呈现在桌面上,而不是在事物中,JSP,Servlet的生活等Web端操作系统特定的一部分。更有点特别,像摇摆(其中有那些JPanels,Jbutton将和等你作为UI组件所提到的),目前 SWT 基于AWT和在它上面工作呈现UI,并允许它正常工作。

AWT is the OS-specific part of UI rendering on desktop, not on the Web side of things in which JSP, Servlets etc. live. A bit more specifically, things like Swing (which has those JPanels, JButtons and so on you mentioned as UI components) and SWT are currently based on AWT and work on top of it to render the UI and allow it to work as expected.

不幸的是这一切都意味着在网页上,因为,你不能使用基于AWT组件以及,网页(通常)与平台无关的意义上,他们没有得到确切决定如何在UI的部分呈现,有只是一个标记一堆被视为一种请求的Web浏览器做的事情网页设计师的希望没有100%quarantee最终的结果将是设计师想要的东西。

Unfortunately all this means you can't use AWT based components on Web pages since, well, Web pages are (usually) platform agnostic in the sense that they don't get to decide exactly how parts of the UI are rendered, there's just a pile of markup which is treated as a sort of plea to the Web browser to do things the Web designer hopes for without 100% quarantee that the end result will be what the designer wanted.

有已经有很多重复发明轮子来实现的Swing / AWT一种在Java的Web端UI制作的,因为它是一个聪明的模式,就像你似乎已经知道的 试图尽自己的本份,让谷歌的Web网页工具包看起来更象一个桌面应用程序,而实际上它仅仅自动化所需的JavaScript阿贾克斯下方使网页的行为,如果它是一个桌面应用程序。这其中的一个另一个框架是挂毯我没有亲自使用,但有些人认为这是一个不错的选择了。

There's been a lot of reinventing the wheel to achieve Swing/AWT kind of UI creation on the Java's Web side since it's a clever model, like you seem to already know Google Web Toolkit tries to do its part to make Web seem more like a desktop application while in reality it merely automates the needed JavaScript Ajax underneath to make the web page behave as if it was a desktop application. One another framework for this is Tapestry which I haven't personally used but some think it's a decent choice too.

再有,当然是我个人最喜欢的阿帕奇检票它可以让你有Java的$之间的真正分离C $ c和标记和它的表现非常类似的Swing UI code呢!事实上有名称冲突与最简单的事情Swing的UI组件类一大堆。假设你的任何熟悉编写一个桌面应用程序的UI我强烈建议检票,它抽象掉枯燥而乏味的部分(Servlet的,URL解析,页面bookmarkability,安全......),并具有类似的事件驱动模型(替换它们但不等于)到Swing的 EDT 这哪里是桌面UI魔术通常会发生的。

And then there's of course my personal favorite Apache Wicket which allows you to have a true separation between Java code and markup and it behaves quite similarly to Swing UI code too! In fact there's a whole bunch of name collisions with Swing's UI component classes for the most simple things. Assuming you're any familiar with coding a desktop application UI I strongly recommend Wicket, it abstract away the boring and tedious parts (Servlets, URL resolving, page bookmarkability, security...) and replaces them with an event-driven model similar (but not equal) to Swing's EDT which is where the desktop UI magic would normally happen.

虽然这会从你要找的内容完全路程,检票您可以创建这样一组可以重用他们在任何地方,从而让你问什么POJO Web组件。虽然警示的话,检票假定你真的知道如何code与Java有些可笑容易的事情可能是乏味的在第一,但最终你应该与你有什么非常高兴。

While this is going completely away from what you're looking for, with Wicket you can create such a set of POJO Web components that you can reuse them just about anywhere and thus get what you asked for. A word of warning though, Wicket assumes you really know how to code with Java and some laughably easy things may be tedious at first but in the end you should be quite happy with what you got.

这篇关于如何创建自定义的Java Web控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆