• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Present A List By Groups (More Related to Design)

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The application I am working on is similar to a message inbox. I first present to the message receiver a list of "subjects", and each subject is a thread of a number of postings.

I have handled this step - I use a ThreadBean to represent "a" discussion thread. The ThreadBean has many properties: threadID, receiver, sender, articleID, articleTitle, postTopic, postBody, threadCreationDate, lastPostSenderName, threadViewCount, threadReplyCout, etc.

I have a method getThreads_forReceiver_withSortSupport( receiverName, offset, rows, sort, order ); to prepare a "Collection" of the ThreadBean. I then iterate through this collection to write out the properties of each ThreadBean in sorted order:

For message receiver: John Doe

Subject A
Subject B
Subject C
Subject D
.....
.....
Subject Z


Now, I want to something a little different. Because people send John Doe messages to talk about a number of different articles, I want to "classify" this "Collection" of the ThreadBean by articleID/articleTitle.

For message receiver John Doe

Article ID 15

Subject D
Subject F
Subject M
Subject Q

Article ID 34

Subject A
Subject G
Subject I
Subject K
Subject O
Subject R
Subject X

Article ID 52

Subject B
Subject C
Subject E
Subject J
Subject N

Note that articleID/articleTitle are properties of the ThreadBean.

A. What should my query string look like to get all the messages for John Doe grouped by articleTitle, and messages are sorted in each articleTitle category?

String query = "SELECT thread_id, message_receiver, message_sender, article_id, article_title, thread_topic, thread_body, thread_creation_date, last_post_member_name, thread_last_post_date, thread_view_count, thread_reply_count FROM message_thread WHERE message_receiver = ? ORDER BY " + sort + " " + order "";

B. To write out this Collection retrieved from the database, there will be a nested iterations - the outer iteration is article groups and the inner iteration is subjects of discussion represented by the ThreadBean. How do I do it?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JiaPei,
A) Your query has the idea. Just make sure to order by the article id field (and possibly a second field if you want to have sorted groups)

B) In your display use a java variable to keep track of the previous and current values. On the first row and when they differ, you can display a header with the article id. It's not neccessary to use nested collections.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Jeanne, for helping me.

Currently, my application provides users a feature to sort all the ThreadBean retrieved from the database according to two criteria:

1. sort by any of the following:
thread_last_post_date, thread_creation_date, message_sender, thread_reply_count, thread_view_count

2. order by DESC or ASC

Therefore, my existing query string looks like:

According to your advice, I simply add another criterion; say, articleTitle to my query string.

A. Will this added criterion articleTitle have any impact on the feature that the application provides to users; namely, sort and order? (Now, all messages will be presented to users in categories; i.e. articleTitle.)

B. Is it default to DESC if I sort by articleTitle (as you know, each title is a long String) and I do not provide DESC or ASC.

C. Where should I add the articleTitle to the query string

C.1: before sort and order?

or

C.2: after sort and order?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JiaPei,
A) I assume you want to sort withing the category? If so, just make sure the articleId field is first in the order by clause. You can add the supplemental sort column afterwards.


B) The default is to sort ascendingly. You need to add DESC to sort descendingly.

C) Option 1 is correct (see comments in part A)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic