How to create custom Java web controls?

This question arose in my head like β€œCan I use AWT controls in a servlet?” which will show all my ignorance on this subject.

I am new to JAVA technologies, but after a little reading I seem to understand that AWT controls directly connect OS GUI elements, so there is no way to use or extend JPanels, JButtons, etc. in the servlet that needs to be inserted into the JSP and allow the browser to display these controls (an alternative would probably be to embed the applet in the JSP, but I don't want to do this).

I am looking for a way to create custom reusable web controls using JSP and servlet.

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

EDIT:. This is part of the test run that I give the Google Engine Engine, so it would be useful for me to study the Google Web Toolkit - any pointers in these directions would also be appreciated.

Any help appreciated!

+4
source share
2 answers

AWT is the part of the OS related to the OS on the desktop, and not on the web side of things in which JSPs, servlets, etc. A little more specifically, things like Swing (which has these JPanels, JButtons, etc. you mentioned as UI components) and SWT are currently based on AWT and are working on it to display the user interface and let it work properly.

Unfortunately, all this means that you cannot use AWT-based components on web pages, since web pages (as a rule) are not platform agnostics in the sense that they cannot determine exactly how parts of the user interface are handled , there is only a bunch of markup, which is seen as a kind of call to the web browser to do what the web designer hopes without a 100% guarantee that the end result will be what the designer wanted.

There was a lot of reinventing the wheel to achieve the creation of the Swing / AWT user interface on the Java web side, as it is a smart model, as if you already know the Google Web Toolkit is trying to do its part to make the Web more like a desktop application at the time as a matter of fact, it simply automates the necessary JavaScript Ajax to make the web page behave as if it were a desktop application. Another reason for this is Tapestry , which I personally have not used, but some consider it a worthy choice.

And then, of course, my personal favorite is Apache Wicket , which allows you to have a true separation between Java code and markup, and it behaves pretty much like Swing UI code! In fact, there is a whole group of name collisions with Swing UI component components for the simplest things. Assuming you are familiar with coding the user interface for desktop applications, I highly recommend Wicket, it abstracts from boring and tedious details (servlets, URL resolution, page bookmarking, security ...) and replaces them with an event-like model (for example, but not equal) Swing EDT , where desktop magic will usually run.

As long as this completely departs from what you are looking for, with Wicket you can create such a set of POJO components that you can use them anywhere and get what you requested. A word of warning, though, Wicket suggests that you really know how to code Java, and some ridiculously simple things can be tedious at first, but in the end you should be quite happy with what you got.

+4
source

In JSP, you're probably looking for custom tags. Custom tags are ways to create reusable code components that will be used when displaying JSP pages. There are some very beautiful ones, such as those found in the struts2 framework or.

But you can write your own or expand existing ones with new features.

+1
source

All Articles