File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Presenting Data to User Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Presenting Data to User" Watch "Presenting Data to User" New topic

Presenting Data to User

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1562
I have remote data in the form of parent child records. My idea is to get this data into a class as array objects. Then present this to the user in a table where the parent data is in the left cell of a table with the child records in the right cells. Then I need to the parent cell to be dynamic in nature so that part of the table could expand and colapse. Is this doable? So far I have the class creating two arrays. One array in a one dimensional array holding the parent records. The second array is a three dimensional array holding the parent, child field1, child field2. I am stuck on haow to get this into my servlet and thn to be presentd on my JSP. I do arrays of arrays all the time with two dimensional arrays but this seems tricky.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
To start with, I would try first to create the HTML for the page with a servlet, rather than a JSP page. I'm not sure if you could present such a complex, homegrown data structure with a commercial JSP tag library, or if it is even worth it to develop your own set of JSP tags.

Writing the HTML directly from the servlet code seems like a good way to start.
[ September 30, 2008: Message edited by: James Clark ]
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
I advice you to write a taglib yourself to build the data presentation. Thus, the servlet build the Arrays, the presentation logic will be placed into the Taglib and your JSP will stay "clear". If you need any changes in the future, you go directly to the taglib.

Regards, Jair Rillo Junior, SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 5.0, IBM SOA Associate (Test 664).
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Originally posted by James Clark:
Writing the HTML directly from the servlet code seems like a good way to start.
I'll respectfully, but strongly, disagree. The only thing worse than putting Java code in a JSP, is moving HTML markup to Java.

I';d start by writing, by hand, the desired HTML construct. And then see if I could use the existing JSTL tags to "JSP-ify" it. If not, I'd then design custom tags to handle it.

[Asking smart questions] [About Bear] [Books by Bear]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
I agree with the statements about having Java code write the HTML from a servlet.

The key part of my sentence was "...seems like a good way to start." There is no need to find the perfect solution on the first try or to get bogged down with all the details, but get nothing accomplished.

The OP seems a bit lost with "how" he can get his data structure to display in an HTML table. The first thing to verify is that this array-based data structure can be manipulated to populate one or more HTML tables. If he can do it in a servlet, he could then move the code into a custom JSP tag at a later point in time. This is the better solution.

There could be other good ways to start, as indicated, e.g. via JSTL tags.
[ September 30, 2008: Message edited by: James Clark ]
I agree. Here's the link:
subject: Presenting Data to User
jQuery in Action, 3rd edition