Two Laptop Bag*
The moose likes Servlets and the fly likes Pagination -- Composite to List? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Pagination -- Composite to List? " Watch "Pagination -- Composite to List? " New topic
Author

Pagination -- Composite to List?

Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
I have a composite list (tree) as an OL.

I want to create links from top to bottom, left to right.
Traversal order:

OL is the root of the list.

It's going to be a list of HTML pages that have "next" links.

There will be two forms of navigation:

1) The tree will be displayed as an <ol> element, with nested <ul> elements. This appears on every page, on the sidebar nav.

2) A "next" link will appear on the page, below the content. This link leads to the next element in the list, based on the above order.

My idea is to create an OL, parse it to a Tree, then get a list from that tree.

I am doing this as a pet project; it should be the simplest thing that could possibly work.

What would you do?

[this forum software is horrible]

[ October 10, 2007: Message edited by: Garrett Smith ]
[ October 10, 2007: Message edited by: Garrett Smith ]

comp.lang.javascript FAQ: http://jibbering.com/faq/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Originally posted by Garrett Smith:
What would you do?
Abandon any notion of parsing HTML for the data.

Supply the data from the backend in a format usable by the JSPs and servlets. HTML is not a data format.
[ October 10, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Is creating a backend the really the simplest thing that could possibly work?
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Could use JavaScript to find the next link.

It would be simple.
It would not be degradable to bots.
It is sort of a misuse of javascript.

But it would be possible, and much simpler than creating a backend for this.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

If you're not interested in a back end, why is this posted in the Servlets forum?

If you want to do all this in the front end, that'd be possible too, but I'd still not use HTML as a data model.

So which is it? back or front?
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
But javascript is then going to be responsible for disabling links on the sidebar. This requires checking the location string, then disbling the current link on the sidebar. It's possible, but messy.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

At this point, I have no idea what you are looking for.
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Originally posted by Bear Bibeault:
If you're not interested in a back end, why is this posted in the Servlets forum?

To me, back end means database.

If you want to do all this in the front end, that'd be possible too, but I'd still not use HTML as a data model.

So which is it? back or front?


I'm trying to get the best angle on the problem.

When I read "back end", I think of db tier.

A server side approach seems like a cleaner way to solve the problem.

Create custom tag that accepts a TreeSet, renders the TreeSet as a list, and sets a treeVar variable on the page. treeVar.next() would display the link.

Not easy. Or simple.

Consider the alternative:
It is possible to disable links based on location.href, and also possible to find the href for the next() link. This is messy.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

back end == not client

And still, to be honest, I'm not sure what you are looking for. It just seems like a simple matter of laying out the markup that will give you the appearance and behavior that you want. Where's the issue that you are having?
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Back to this diagram:


Req:
The OL is a list of ( links and lists of links ).
Each page shows this list. The current page's link is disabled.
Clicking next() gets the next link using depth-first search.


What's the right way to do approach this complexity?

What is the simplest way to solve the problem?

Option 1. use include:
<jsp:include page="nav.jsp"/>

I could disable the current link based on location.href.

I could then set next() link's href based on the Depth-first search.

Writing a DFS in javascript would not be that hard, but seems like not the right way to do it.

Managing the content on the server seems less hackish.

What would you do?
[ October 10, 2007: Message edited by: Garrett Smith ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I'm not sure what an "OL" is, but yes, I would do the work on the server. Based on the current node, I would generate a page containing the information for that node and a link that goes to "next". When this link is clicked, my servlet would find what "next" means, set the current node to that, and generate the page.
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
"OL" means "ordered list".

Paul, can you provide more details on the solution you proposed? I don't know how to do that.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Just like Bear said:
Supply the data from the backend in a format usable by the JSPs and servlets.
So you're going to have your tree structure somewhere in the server. You will generate the ordered list display from that tree structure and, given a node in the tree you will find out which node is the next node.

I noticed a lot of remarks about "disabling links". I'm not sure what that was all about, but if you're generating the links at the server based on the tree structure, you can certainly generate them disabled, or you could generate HTML that didn't even include them.

The main point to be made here is that you don't generate a display (HTML) and then try to fiddle about with it once it's displayed. You keep the data in the server in a usable form on the server, and generate suitable HTML from that based on the context and what the user requested.
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
Originally posted by Paul Clapham:
Just like Bear said: So you're going to have your tree structure somewhere in the server. You will generate the ordered list display from that tree structure and, given a node in the tree you will find out which node is the next node.


So how exactly do you do that?



I noticed a lot of remarks about "disabling links". I'm not sure what that was all about, but if you're generating the links at the server based on the tree structure, you can certainly generate them disabled, or you could generate HTML that didn't even include them.

Ideally, it seems better to do it on the server side.


The main point to be made here is that you don't generate a display (HTML) and then try to fiddle about with it once it's displayed. You keep the data in the server in a usable form on the server, and generate suitable HTML from that based on the context and what the user requested.

Do you know how?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pagination -- Composite to List?