I'm just getting involved with Servlets, Tomcat, JSP etc and was wondering what people typically use for GUI's in their JSP pages (for client-side interactivity). I've used jQuery, YUI, extJS, etc. for JS scripting in simple webpages, but what about for web applications? Do these client-side technologies integrate well with JSP pages? Are there tag libraries out there to help with this sort of thing?
Any suggestions?
As a specific example, would it be a good idea to populate a YUI DataTable using JSP embedded in the JavaScript?
For rich GUI, consider looking at JSF. There are lot of JSF component libraries around which offers GUI awesomeness, for example PrimeFaces. It's basically using jQuery / jQuery UI under the covers. Checkout for example the Mock OS X demo.
If you don't want to bow for a component based MVC framework like JSF, then you can also just go ahead with "plain" jQuery / jQuery UI. It shouldn't be that hard on JSP. All JSP basically does is generating and sending some bunch of HTML/CSS/JS code from webserver to webbrowser. All JavaScript/jQuery basically does is intercepting on the HTML DOM tree as the webbrowser has retrieved (in other words, it has totally no knowledge about the server side JSP code which generated/sent it).
You only need to realize that afterwards bringing a component based MVC framework in an existing JSP/jQuery webapplication isn't that easy. Rather look for a request based MVC framework like Spring MVC then.
Related questions
What is the need of JSF when rich UI can be achieved by plain HTML/CSS/jQuery?
You can use any of those libraries. I personally prefer jQuery. I've also used prototype and Ext JS in the past. Some frameworks integrate proprietary or generic Ajax approaches, but I find the popular ones (such as those you listed) to be a better alternative.
Related
I'm in the "technologies selection" phase of a small, single-page web application that will be heavily-based in AJAX, and which will report to a Java backend.
In a previous question I posted several weeks ago, the SO community at large felt strongly that I would be better off going with a Spring MVC-based web app than with something in JSF. Since Spring is request-oriented, and JSF is component-oriented, it would only make sense to use Spring for something that is going to be getting a lot of asynchronous requests.
If I were going the JSF route, then my next set of decisions would be whether or not to use so-called UI component libraries for the view technology, such as PrimeFaces, IceFaces or MyFaces.
So, I'm wondering: Does Spring MVC have anything similar to, say, PrimeFaces (or its likes) for creating the view component for my page(s)? I know its not component-based, but I'm not all that familiar with Spring MVC's web platform and was wondering what are some de facto standards (if any) or typical technology stacks that Spring web developers use for constructing nice web pages.
And, if Spring just uses run-o-the-mill template engines, would something like Freemarker suffice?
I guess this is a "best practices"-type question for a budding Spring web developer.
Thanks in advance!
Typically, the value so-called UI components lies in how they keep track of user interactions on the server side by integrating with a stateful framework.
Since you have decided to go for a request oriented framework, it would make more sense to use some well-known client-side JavaScript libraries instead. Popular choices include:
Backbone.js – an MVC foundation for user interfaces
jQuery UI for some premade widgets (calendars, etc.)
If you want to go down a more complex route, but with a more desktop-like feel, Sproutcore
Finally, if you wish to avoid JavaScript, you can useGoogle Web Toolkit, which compiles Java to JavaScript and is supposed to have good integration with Spring.
Personally, if I don't need a lot of standard prebuilt widgets, I like Backbone.js + underscore.js + jQuery. I don't like Google Web Toolkit since it feels like writing a pidgin JavaScript, and at that point I prefer to write JavaScript directly.
Yes, JSF is component oriented and Spring MVC is request oriented.
I recommend you to have a look at Thymeleaf Template engine, which is a complete replacement for JSP Engine
....
Thymeleaf Features are:
It allows natural templating.
HTML5 support
Higher performance by utilizing in memory caching
Click here for more
Additionally apart from the things mentioned by Ludovico Fischer, if we consider the same question in now a days tech world than you can use one of the most power full thing of recent world : Angular. There are 2 sample scenario's.
If your architecture is full client side: The integration is very natural for it. Spring MVC expose your service as a REST (JSON / XMl ... ) and your client application with Angular JS consume your JSON. Here the war application (Spring mvc ) must be deployed in a Servlet Container (Tomcat) and your client application can be deployed in the same server or in another server Nginx , Apache etc..
If you want to keep page generation in the server side and only use AngularJS for some nice DOM manipulation so your code must be deployed in the same war (WEB-INF). Mixing the two approachs is not always a good idea. You can try thymeleaf to stay in server side page generation.
Thus in this way you can have simultaneously the cool featuresof angular like templating, testability and clean view code.
Here is another approach (Not JSF) to let Spring MVC to work with ZK UI components - Rich Web Application with Spring MVC CRUD Demo
In that article, it used Spring MVC controller to communicate with ZK UI components. (all in Java code)
I'm looking for a java framework to develop a website that will contain various AJAXy style components on it, but will use tradition page refreshes when switching between pages. I understand that there are a lot of java based frameworks for building web applications (GWT, ZK etc.) but from what I can see these are good for building swing style web applications rather than traditional websites with Ajax components.
So my question is what java frameworks would you suggest using for this case?
Almost any (good) JS component library will allow you to insert the library components (UI widgets) into your multi page application.
Typically, your page loads and on load, you instantiate the (AJAX enabled) UI components and insert them into the page's DOM (usually bind them to some placeholder div tags on the page)
With the above concept out of our way, you want to look for a library or combination of libraries working together that
-Have the UI widgets you are looking for.
-Integrates (fairly easily) with Java.
Following possible options come to my mind
RichFaces with JSF as mentioned by the above poster.
YUI and DWR combination
ExtJS + directjngine
I am sure there are a lot more options but ones listed above are the ones that I have used successfully on production projects.
In my opinion WWW will sooner or later come to full-blown AJAX web-sites, so that we wouldn't have
page reloads every time you click somewhere.
Now I want you to ask this.
What tools and frameworks can one use to make a Java Web-application running on Tomcat
have AJAX functionality like "in-place, with no page reloading" table sorting by
clicking on its column header, multi-tabs that enable opening at once the new screen to the user without reloading a page, saving data in the database without reloading a page, and other similar things that we do not usually see on web pages.
That's all should probably be based on AJAX.
But how to integrate this AJAX functionality with existing java web-frameworks, let's say Spring MVC?
Or maybe there are other frameworks that better suit such needs but that can be integrated with core Spring?
Your question is rather confusing--AJAX calls are all client-side, any server-side technology can return data to the client.
That being said, you may try taking a look at Google Web Toolkit.
With the GWT SDK, you write your AJAX front-end in the Java programming language which GWT then cross-compiles into optimized JavaScript that automatically works across all major browsers. During development, you can iterate quickly in the same "edit - refresh - view" cycle you're accustomed to with JavaScript, with the added benefit of being able to debug and step through your Java code line by line. When you're ready to deploy, the GWT compiler compiles your Java source code into optimized, standalone JavaScript files.
Among other things, GWT supports built-in serialization of objects for transfer to your Java servlets, allowing for crazy-easy (the technical term) integration of your GWT client and existing Java technologies.
Homebrewed/3rd-party Ajax stuff with JSF isn't that easy since you have to take its lifecycle and component tree into account. You would need to write your own ViewHandler. Rather look for what's already available. To start, JSF2 already provides builtin Ajax functionality with under each <f:ajax>. There are further also a lot of Ajaxical JSF component libraries, like RichFaces (showcase here).
No wording about Spring as I don't do it.
I'm looking for a java AJAX framework which I can include into my existing webapp. I've found sweetDev RIA . Are there such other frameworks which I could look into it?
I'd take a look at DWR: Direct Web Remoting. It allows you to directly call Java (web services) from JavaScript in a really intuitive way.
Last couple of years, I have been developing rich looking web applications with icefaces. It is pretty cool, ajax is buit-in and it blends very well with jsf. If you use icefaces, javascript is not required anymore. In our web project we use javascript only in couple of places.
Here is an excerpt from icefaces homepage: "As a leading open source Ajax framework, ICEfaces is more than a Ajax JSF component library, it's an J2EE Ajax framework for developing and deploying rich enterprise applications (REAs). With ICEfaces, enterprise Java developers can easily develop rich enterprise applications in Java, not JavaScript."
I suggest ExtJS (with jQuery underneath), but you might prefer GWT. I think it's easier for Java programmers who are seeking to wade slowly into JavaScript waters.
I would really check out extjs.com. It is the most feature complete javascript component library I know of. The components are fast, have beautiful default styling, and the API is very powerful. AJAX support is also excellent. Most of my current web development include extjs in some way.
It's very easy to use this library with java. Most of the time, I just have some server side component that returns data in JSON.
There is also ExtTLD; a tablib wrapper for extjs. I have never used it myself, though.
Google Web Toolkit ( GWT )
you can also use Apache's 'Myfaces' project http://myfaces.apache.org
Its a JSF implementation, and also has components with in built ajax capability.
You can try SweetDevRia, it's possible to add ajax in your application without writing Javascript. You only need to use JSP tags
I was recently asked in an interview - In java, how do you compare component based frameworks to request based frameworks? I explained EJB as an example of Component based framework and Struts as a request based framework but was not convinced if I did justice to the question.
Any ideas on what interviewer meant and what should have been compared??
regards,
avajurug
They were most likely looking for examples of web frameworks - for example, JSF is a component-based framework, and Struts is a request-based framework.
Request-based frameworks generally make it clear through their APIs that they're working with parsing an HTML request / generating an HTML response, while Component-based frameworks attempt to abstract this away and treat the application as collections of components with renderers and actions to do things.
In my opinion, component-based web frameworks are more trouble than they're worth - their main purpose is usually to make the development of a web app "easier" for developers unfamiliar with web development, and closer to traditional desktop development. However, in practice, when something goes wrong, you need to develop custom components, you need to customize the framework for something that isn't "out of the box" functionality, etc. you need to understand both underlying "traditional" web development and how the component-based framework abstracts it - and if you're an experienced web developer and have existing solutions, utilities, libraries or snippets that worked in "traditional" web development, you'll waste time re-implementing them to work within the component-based framework.
Request based framework is a web framework that gets user's request then determine what the system should do and give back the response back to the user. So the flow is pretty much linear. You're thinking in actions: what does user want (request) -> what user will get back (response). An example of Request based framework is Struts. The modern Grails is pretty much a Request based framework too.
Component based framework is not like that. There is actually no clear sense of the flow from front to back. An example of it is not JSF, because in some way JSF is pretty much quite the same with Struts (since the creator of Struts and JSF is the same). A good example of Component based framework Tapestry and Wicket. The paradigm in these two framework is different. You don't think in actions or request-response, but components and components. You define a component in your application, and you tell what the component does. But the flow does not have to be linear as in Request based framework.
JSF is component based java API, as said Nate, Struts is an action based framework, the Http requests are parsed, while processing the actions in the end the controler Servlet forwards the request to the JSP that will be responsible to generate the response. While in JSF which became a standard for component based web frameworks, there is actually no need to process the requests and the responses as all we need is to write JSP or XHTML pages, bind the components used in the page or the value they should render to properties in backing beans or managed beans and the FacesServlet (controller) does all the job to care about request parsing and redirecting to the JSP that will render the response based on navigation rules specified in faces-config.xml . So as you can see there is a big difference between Struts and JSF as JSF brings a component-event based approach while Struts is more close to the classic JSP/Servlet model. Another thing jpartogi have said the creator of JSF and struts is the same, I just want to mention that Struts is a framwork owned by Apache community while JSF is an API specified by JCP in the JSR-127 for the version 1.1 and JSR-252 for the version 1.2 and has different implementations (SUN-RI, Apache MyFaces...)
Simply, If the framework has objects in java side for each web element so you can change attributes of it or add some functionality, it is component based framework but If framework does not provide objects and you have to put the response value of web element between its tags it is a request based framework.