| By Anil Hemrajani | Article Rating: |
|
| July 24, 2006 01:00 PM EDT | Reads: |
38,816 |
Figure 5 shows a sample forms screen that can be developed in JSP using Spring's bind tag library. The Spring bind tag library is simple yet powerful. It's typically used in JSP files via the <spring:bind> tag that essentially binds HTML form fields to the command object. Furthermore, it provides access to special variables in JSP that can be accessed using JavaServer Pages Standard Tag Library (JSTL) expressions such as ${status.value}. The code excerpt below demonstrates how the spring:bind tag library works - notice how we bind directly to the Department domain (business) object that we looked at in the Hibernate section:
<spring:bind path="command.departmentCode">
<input name='<c:out value="${status.expression}"/>'
type="text" size="10" maxlength="30">
</spring:bind>
Besides spring:bind, Spring 2.0 introduces some new tag libraries that ease working with individual HTML form elements. Some of these include form:input, form:textarea, and so on.
Spring MVC Configuration Concepts
Till now we've only
looked at Java-related concepts for Spring MVC. Of course Spring also
has configuration aspects. For starters, its DispatcherServlet class
has to be configured in the Web server's Web.xml file, so files
matching a certain extension (like .htm) can be processed by Spring
MVC. Once this is configured, we're in the world of Spring MVC. From
here, we configure view resolvers and handler mappings in a Spring
application context file. View resolvers map incoming URLs to actual
view names. Handler mappings map incoming URLs to controller classes.
Spring ORM
One of the beautiful things
about Spring is its support for third-party APIs such as JDBC, JAX-RPC,
Hibernate, and many others." For example, if we use Spring with
Hibernate, we can eliminate the code required to manage Hibernate's
sessionFactory, session and programmatic transaction management. The
benefits of using Spring with Hibernate is that it cuts down the
Hibernate-related code by almost a half and provides additional
benefits such as easier testing, consistent exception hierarchy, and
management of Hibernate resources.
Visit springframework.org for more details.
Effectively Developing Java Code with Eclipse
In
my book I have a chapter dedicated to the Eclipse SDK. Initially I
planned to use a generic title but later I changed it to "The Eclipse
Phenomenon!" because that's the best way to describe what's happening
in the Eclipse community. No matter how good another Java IDE might be,
the sheer number of plug-ins available for Eclipse is hard to match. If
you do a search for the words for "eclipse plugins" on the Web, you'll
literally get millions of matches. In other words, the Eclipse
community is exploding!
The Eclipse platform is essentially a framework that provides a set of services that other plug-ins can build on. Each plug-in is developed to the same platform, which translates into a set of highly integrated tools. The Eclipse Web site currently has many sub-projects underway including everything from support for various programming languages to modeling plug-ins to reporting, testing, and performance to almost everything else required for software development.
The core concepts of Eclipse include a workspace, essentially a directory for your projects. The first main screen in Eclipse is known as the workbench (see Figure 9). The workbench contains a set of editors and views organized as perspectives. Perspectives are task-specific layouts of editors and views.
One of the core Eclipse plug-ins is the Java Development Tool (JDT). It's an extremely robust plug-in with support for Java development such as managing Java-related files (.java, .class, and .jar), Java views, compilation, code formatting, debugging, refactoring, and syntax highlighting - in fact, the JDT plug-in is a full-blown product in itself.
Another important plug-in is the Eclipse Web Tools Platform (WTP), intended for developing JEE Web applications. It provides editors like JSP, HTML, CSS, JavaScript, and WSDL. It also provides extremely handy database query and model tools to explore the database, run queries, and analyze the data. Of course, the ability to create and test Web Services easily is another major feature of this plug-in. JDJ published a series of articles by Boris Minkin on using WTP (see java.sys-con.com/author/minkin.htm).
Apart from the plug-ins provided on the Eclipse.org Web site, there's no shortage of plug-ins available for Eclipse on the Web. Sites such as eclipseplugincentral.com, eclipse-plugins.2y.net, and myeclipseide.com have a large number of plug-ins.
Other Eclipse features include team support via tight integration with CVS, a robust help system, a large number of preferences, and shortcut keys.
In short, Eclipse provides tools to work on all tiers of an applications, that is, data, Web, and business.
Beyond the Basics
If we lived in a perfect world,
we would simply gather user requirements, code them, and deliver
perfectly stable applications that would run smoothly without
intervention. However, as developers, we know it doesn't quite work
that way and that there are times to troubleshoot problems or monitor
the "health" of our applications; so, let's review some techniques that
can help.
Debugging
Debugging is typically a
process of locating and fixing a defect, although it can also be used
to step through code to ensure the logic works right. Eclipse's JDT
plug-in provides a powerful Java debugger that lets us debug local Java
programs or ones running on a remote Java server. Like most debuggers,
the Eclipse JDT debugger can step through code (one line at a time or
by jumping to a breakpoint) and inspect variables. It also provides a
very useful feature known as Hotswap that lets us change code
on-the-fly, recompile, and continue debugging in the same session. This
is a handy feature since setting up a debugging session just the way
you want it can take time. Figure 10 demonstrates
how we can debug our Java code, see the data in the database, and see
the console output - all in a highly integrated fashion using two
completely different plug-ins JDT and WTP.
Profiling
Java profilers have been around
for almost as long as Java. Among other things, they let us analyze the
heap for memory usage and leaks, CPU utilization, trace objects, and
methods, and determine performance bottlenecks. A variety of Open
Source profilers are available out there, as well as commercial ones
(like YourKit Java Profiler and Quest's JProbe Suite). Some run as
standalone Java programs; others can be deployed to a servlet
container; and still others are available as Eclipse plug-ins. So, if
you're looking for an Open Source profiler,: www.manageability.org/blog/stuff/open-source-profilers-for-java/view/ lists a dozen of them.
One other profiler that's supposedly one of the best is the NetBeans Profiler, however, I haven't tried it out yet but the screenshots look sleek. Visit profiler.netbeans.org to learn more about this.
Logging
Logging is an important aspect of
software development and varies from print statements to complex
database-based logging. Logging types can include audit logging,
tracing, and error reporting.
Two logging frameworks commonly found in the Java world are Apache Log4J (logging.apache.org/log4j/) and JDK logging (java.sun.com). Another option is to use Apache's Jakarta Commons Logging (jakarta.apache.org), which provides a thin bridge between various logging frameworks, including Log4J and JDK logging. While we can use simple print statements to output messages from your programs, logging frameworks let us control the output of our messages according to destination (files, database, remote), levels (fatal, error, warning), and format (date and time). In addition, logging frameworks provide benefits such as automatically rolling over log files when they reach a certain length.
Monitoring
Java Platform Standard Edition
(JSE) 5.0 provides built-in remote monitoring, management, and the
JConsole Swing-based utility (see Figure 11)
to monitor applications that run using JSE 5.0 or later versions. These
tools can be used to view the resource utilization of Java
applications. For example, it can help detect memory issues, class
loading, and garbage collection, control JDK logging levels, and manage
an application's Managed Beans (MBeans). Furthermore, Spring's JMX
support lets us automatically register POJOs, which gives us a powerful
paradigm because we could easily write business-type objects that can
be monitored (instead of the typical low-level technical stuff). For
example in our sample application, this could include the number of
timesheet records fetched and the number of logins.
Conclusion
We've covered a lot of ground in this
article. As I mentioned at the beginning, this is a road map for one
way of doing agile Java development. However, what would an article in
a Java magazine be without some Java code? So I have a completely
functional sample timesheet application, downloadable (and a deployable
war file) at visualpatterns.com/resources.jsp. The resource section below also provides a summary of links specified throughout the article.
I hope this article has provided some guidelines for developing Java in an agile manner. Cheers!
Resources
- Agile Data: agiledata.org
- Manifesto for Software Development: agilemanifesto.org
- Agile Modeling: agilemodeling.com
- Scrum: controlchaos.com
- Eclipse Foundation: eclipse.org
- Extreme Programming: extremeprogramming.org
- Hibernate: hibernate.org
- Martin Fowler: martinfowler.com
- The Spring Framework: springframework.org
- Test Driven Development: testdriven.com
- Author's Web site: visualpatterns.com
Published July 24, 2006 Reads 38,816
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Anil Hemrajani
Anil Hemrajani is the author of the book titled Agile Java Development with Spring, Hibernate and Eclipse. He is the founder of Isavix Corporation (now InScope Solutions, Inc.), a successful IT services company, and DeveloperHub.com (formerly isavix.net), an award-winning online developer community that grew to over 100,000 registered members. He has twenty years of experience in the Information Technology community working with several Fortune 100 companies and also smaller organizations. He has published numerous articles in well known trade journals, presented around the world, and received and/or nominated for several awards. Anil can be reached via his web site, VisualPatterns.com.
![]() |
JDJAgile 07/27/06 07:33:07 AM EDT | |||
Hey Jeff, JDJ used all of the lastest Agile methods to develop their pages, so you see it's fast, it's now, it works! Far be it from me to stand in the way of progress. Give me a break, none of this crap has infiltrated coporate computing in the least. Just go back and code like the rest of us and stop patting each other on the back for your supposed genius. I'm sure the author is well-meaning but when we're bombarded daily with titles like "The Four Quantum States of Ajax" I just gotta laugh. Do you really think all this stuff is changing anything?! The engineering world wants real engineering not something built on top of existing frameworks decades old that works and works well. |
||||
![]() |
Jeff 07/25/06 10:48:49 PM EDT | |||
Holy crud, the pop up ad blocks the entire story even at 1360 x 768. Do you really need an Ad that big that requires a click to close? There are already adds on both margins and the in the header and Footer, the content is a thin ribbon down the center that get blocked by yet another ad. Just seems silly to me. |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?









































