Better Java Web Frameworks
Better Java Web Frameworks
Join the DZone community and get the full member experience.Join For Free
How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.
I have been doing web application framework development for a long time. In my first experience, we developed a “Web Application Framework“, to ease development so that even a business user could write an application. As the years passed, I never saw any business user writing applications because of the fact that this job belongs to programmers. Today some 4GL or DSL tools are still on the search of the same promise. Before writing our own framework, we had used WebObjects development tools, for Java web development. It was a very good platform that allowed front-end GUI development from a GUI editor with a component model. Every web element can be used as a component and it had events like “clicked”, and click handler Java code can be added with double-click in GUI editor. One disadvantage was portability that you were bound to this platform and its Application Server. This model is similar with Visual Studio ASP.NET development environment that was presented years ago from the .Net emergence. Years later, JSF tries same model.
Web Application Frameworks meet the web application requirements. It is hard to define its border, but it should at least support a presentation layer. It may expand to a “Business Logic” layer or a data access layer. In Java, we have following technologies for web development; JSP, Servlet, JSF, EJB. There are many Java-based web frameworks: Struts, Spring(Spring MVC), GWT, WebWork, Tapestry, Apache Wicket etc.
The power of Java and richness of web technologies have produced many web frameworks (and that's not even considering internal frameworks). It is getting harder and harder to find a compatible development environment. Even some of vendors are pushing scripting languages for “Ease of Development”, another interesting move is “Cloud Computing”. I don’t favor scripting languages for enterprise web application development for “Ease of Development”. On the other hand, “Ease of Development” is a very important topic for programmers (this includes both “Ease of Testing” and ”Ease of Deployment”). “Ease of Development” is closely related with productivity. As development environment complexity increases, development becomes harder thus productivity decreases. Today, we witness low-productivity in many software projects. Low-productivity results in low quality and delays in projects. We need better, simpler and yet powerful web frameworks that truly understand web architecture and its requirements. It is very important to make value proposition of framework before accepting.
Choosing A Java Web Framework: A Comparison
Choosing a JVM Web Framework
The API Field of Dreams – Too Much Stuff! It’s Time to Reduce and Simplify APIs!
Rethinking JSF - The Real Problem
Criticisms of Spring, Struts, PHP, and Rails
Here are required features of a web framework according to our enterprise application development experience:
- Includes all core application layers (MVC)
A web framework should include data access, business logic, controller and presentation layers internally. As frameworks turn out to be an integration hub, it loses value. Every integration among the core layers introduces new complexity, new glue code, new dependency, and conflict of intersecting features. If data access layer (Model) uses another framework, presentation layer (View) uses another framework, integrating these frameworks adds a very big challenge even if frameworks support each other.
Replacing any framework causes many new problems later. For example, JPA is developed for data access independence but at this time you are limited only the features of JPA. IDE is a major development tool, but at this time we need an “Integrated Development Frameworks” environment within IDE. (Similar with ERPs that brought together enterprise applications under the same umbrella)
- Avoids heavy-componentization:
With heavy-components, we lose declarative programming to some degree. We lose “Web Graphics Designer” ability to edit web pages because of moving from design-time to run-time and moving structure information from HTML to programs (while losing HTML Editor functionality). A web editor’s favorite structure format is CSS files so what about CSS componentization?
Another problem is architectural. A web GUI has 2 runtimes; server and client (Browser). In previous years, web frameworks supported only server-side functionality. Today we see client-side-only approach. I think best solution is balanced mixture of both client-side (JS) and server-side code with component templates (not hard components but light partial HTML+JSP+Servlet codes). I will discuss this further, there are already many discussions about “Component-based” versus “Action-based” frameworks on the web.
- No new tag markup or page template:
- No XML usage:
Heavy XML usage for configurations makes programs hard to develop, hard to understand, hard to test. One example is “Page Flow” information in XML files. Another example is bean configuration. Yes, pulling this information makes it flexible but who needs it? How many times does your page flow really change? How many times did we utilize flexible bean configuration? What about source code readability? I don’t like “Dependency” or “Dependency Injection”. I think dependency is not free as you have to manage its subtleties. Here is my anti-pattern “Dependency Rejection”. XML can be used in other useful places like AJAX messages or data import-export.
- Has its own web GUI page elements:
Rich web elements (say light components) are generally found only in JS or AJAX libraries. Web frameworks should provide rich elements like; Calendar, Dialog, Menu, Popup, Progress Bar, List, Grid, Tab (With sub-levels), Master-Detail Windows, Child Windows, Record Navigator etc. Developers can easily extend these elements. We are still turning around simple features like table sorting, filtering etc. We should step ahead. There is still no desktop-like web grid components to use (I see this only in JS libraries) that I mentioned in my previous blog post.
- Code generation:
Code Generation makes “Rapid Development” possible. Every piece of software should be generated (Generative Programming); CRUD data access classes, business code, controller code, and view pages. Code generation takes development one step ahead of “Drag and Drop” WYSIWYG editors. If a web framework facilitates code generation, developers could jump to customization details of application instead of building everything from scratch (MDA).
- AJAX support (Asynchronous Communication):
AJAX eliminates page-refreshes. Web frameworks should properly blend AJAX functionality into their code architecture. AJAX requires server-side coding. As we make client runtime powerful with AJAX, GUI state management code is duplicated. For example, if we update and fill a combo-box with AJAX call then server-side bean that is bound to this element is not aware of this state change. We have to change server-side state as well. AJAX functionality should be implemented without code duplication (Another interesting trend is AJAX MVC).
- Portable among application or database servers:
Application and database portability is not easy. In Application Server side, class loader policies change, session management changes, deployment model changes etc. In DBMS side, join clauses change, paging, and sequence generating changes. Web frameworks should provide portable packages for different platforms. On the other hand, some web frameworks have their own IDE and Application Server (believe me even DBMS). I think we must leave this job to the famous products (IDEs and Application Servers in the market).
- Input validation:
Data input validation is a very important feature. If validation doesn’t occur in an application, database errors occur. Database errors are not user-friendly. Some validation errors may not be related to database. Programmers need automatic validation according to database object metadata. Custom validations should be added if needed.
Because of bugs in frameworks, all average developers become framework experts spending valuable time to figure out the problem. “Focusing on business problems” is lost. I have read many open source framework hacks and workarounds in many blogs, which is not the task of a developer.
- Handles exceptions in a user-friendly way:
If error or exception occurs, user-friendly messages should be returned. Application programmers have some responsibility for this but web frameworks may ease this task.
- Eliminates double-click, double-submission problems:
Double-click may cause double-submission. Double-submission may cause unexpected errors in application (2 threads trying to do same thing). Web frameworks can eliminate this problem even in client-side without going to server.
- Authentication and authorization support:
User login (authentication) is still developed by programmers without knowledge of SQL-Injection attacks. Web application authorization is still missing. Who will be granted CRUD access on which application etc.?(User roles, permissions) I am sure that in every enterprise web application, application authentication and authorization is re-invented.
- Security controls for web attacks:
Web frameworks should prevent web security attacks like; Cross-Site Scripting (XSS), SQL Injection, URL Manipulation, HTTP Injection, Session Hijacking etc. Web client data is un-trusted and open to tampering so this is why we can’t quit totally server-side validation for the sake of client-side validation.
- Reporting integration and barcode support:
Reporting integration is important. We need reporting products/frameworks integration. Would you use your data access objects in your reports? Would your reporting engine use the same JVM runtime? Barcode is not a general requirement but in ERP applications it is very useful (AI/DC Automatic Identification/Data Capture). Barcode printing, barcode reading and matching may be provided by your web framework.(What about RFID?) Would your reporting product support barcode?
- Messaging and workflow integration:
Web frameworks may support easy integration with messaging (JMS) and workflow products. Workflow is one of major element of BPM (Business Process Management). In some middleware stacks, this is included (i.e. JBoss Seam jBPM). Web application frameworks may support business events and workflow activities. These events can also be used to feed the messaging backbone (ESB).
- Application to application integration (i.e. Web Services):
In Java, there is external system (EIS, legacy) integration API, which is JCA, but inter-application communication within same JVM is not standardized. Let’s say we have two applications and one should use some call to the other's application code. There is no standard for this. Basic solution is just adding other application’s path into its class-path and then using other application objects. We developed an Adapter API for standardization of this. In one-application environment, this is not a problem but if many applications are required to communicate, it gets more important. You can even convert your APIs into web services when necessary (integration with remote or non-Java systems). Web frameworks may provide tools for web services code generation, deployment and monitoring.
- Admin application for run-time process and user session monitoring:
This is very important in the case of user and system management view. What are my users executing at the moment? Which applications take longer to finish? Which users are on-site? Which pages are they surfing? In each session, which objects are they created? What are the URLs that a user requested? Which SQL statement did a user execute?
- System resource management:
If your application runs big queries that require a lot of system resources (CPU, RAM, DISK I/O), we are faced the reality that resources are limited. If applications don’t restrict user processes, then system will consume its all resources and will not respond to even small processes. For the sake of system availability some user may be rejected by system. The web framework may have such limitation API’s.
- Cluster support:
When server load is high and performance is a major concern, load-balancing is required. Application server clustering will not suffice, web frameworks must support a cluster architecture. One simple example is framework’s id generators. They will collide in clustered Application Server environment.
- Multi-database, multi-company, multi-window, multi-session support:
The application user may need to work on multiple database instances. One user may have to work with multiple companies. The user may want to use multiple GUI windows. Web framework should handle or prevent state corruption among windows. The user may need to work on the system with many sessions.
If there are global users, then i18n support is important. One key aspect here is that the Application Server and DBMS should also support your localization.
- SSL support:
If the web application is required to be secure in insecure networks, SSL-support is important. SSL deployment in an HTTP Server would not be enough. Even if SSL is not used, frameworks must encrypt sensitive data between client and server, like user passwords.
- Document attachment:
In every enterprise application, document attachment is important. Users may want images or Excel documents attached to their application records. Every programmer first search for an upload utility then tries to understand server document folders. Instead, built-in functionality saves valuable time.
- Mobile device support (i.e. Internet Explorer Mobile):
If we want to plan mobile access to our applications, how can we do this with web technologies? Many mobile devices have built-in web browsers and we may run our applications in these browsers. Web framework mobile support would be very beneficial at such cases. Otherwise, you should explore mobile web browser limitations by yourself.
- Portal features:
Partial web components should be supported to use in Portals or external sites. In portal terminology, its name is portlet. There are many synonyms; Widget, Mashup etc.
Application tasks may be batched and scheduled. After task completion, users may see results.
- Keyboard hot-keys:
Users, especially old TUI (Text UI) users want keyboard hot-keys. Buttons, command icons should be bound to hot-keys. Web frameworks elements can support this instead of developing in every application.
- Alerts between users:
Users may want to send messages to each other or system admin may want to send messages to users like notifying a shutdown or an application restart. This feature will be very handy.
Since this list is long enough, I had to skip the following features (plus non-functional features): email support, back button, page navigation, bookmarkability, post-get support, formatters/converters, page skins, context-sensitive helps, URL manipulation, caching, logging etc.
This feature list is application-centric. A web-site-centric feature list may have different items. In web development, these two camps (web-based application developers and web-site developers) are joined and have some conflicting requirements. Scripting languages (PHP, Ruby or Groovy) and RIA platforms (Flex, Silverlight or JavaFX) may be much more appropriate for web-site developers. This is a controversial issue and differentiates framework architecture. In this aspect, we say that some web frameworks are much more appropriate for web-site development and don’t fit into enterprise application development.
Published at DZone with permission of Adam Brown . See the original article here.
Opinions expressed by DZone contributors are their own.