This question
is designed to gauge a candidate's understanding of how JavaServer
Pages (JSPs) work with multi-value JavaBean properties. It addresses
several aspects, but would be most appropriate when interviewing
intermediate to advanced web developers.
One
way in which database information can be displayed in a JSP
is through the use of JavaBeans. What support do JSPs provide
for JavaBeans with multi-value properties (for example a property
called "Students" that returns a list of users)? Such
values are often encountered in J2EE applications that pull
records from a database. What are the different approaches
you might take to display property values such as this in
a page, and what problems could you possibly encounter?
The depth of the candidate's answer will show their familiarity
with not only the JSP API, but also their general level of
experience in working with data-driven J2EE applications.
JSP's built in action tags do not provide the ability to access
multiple values from a single property. The
< jsp:getProperty >
tag can only access single, scalar bean properties such as
a String or int value. To access multi-value properties, also
known as indexed properties, the developer can employ one
of several approaches.
The easiest, and
most straightforward approach is to use scriptlets (in-line
snippets of Java code) to loop through the property's values.
This is the approach most JSP developers will be familiar
with.
Another option
is to use custom tags. Custom tags extend the JSP tag set
to include such activities as iteration, and can deal with
multi-value properties quite easily. A number of 3rd party
tag libraries are available; including several good open source
ones. One of the open source tag library projects, Jakarta-Taglibs,
will become part of Sun's JSP Standard Tag Library. Alternatively,
a developer may point out that they could write their own
custom tags specific to the application in question. While
this is often a good approach, it does require a higher degree
of development skills.
A third approach
that a creative candidate might propose is designing the beans
such that they no longer have multi-value properties, such
as by employing a cursor scheme where a bean uses a single
property to rotate through all of the values.
An experienced
candidate will point out that if the data is coming from a
database, it may need to employ pagination strategies - exposing
a subset of the results spread over several screens - in order
to not overload the browser. Familiarity with the J2EE Page-by-Page
Iterator (or Value List Handler) design pattern would help
to indicate that the candidate is well versed in solving this
problem.
About the author
Duane Fields is a Java developer, author, and Internet technologist
with nearly a decade of professional experience in the design
and development of leading edge Internet products and services.
Duane is also a respected member of the Java development community
and is frequently invited to speak at industry conferences
and events. He has co-authored two books and published numerous
articles on many aspects of web application development from
Java to Relational Databases. The newly expanded, second edition
of his best selling book "Web Development
with JavaServer Pages" was released in December
of 2001.
|