aspose file tools*
The moose likes JSP and the fly likes Displaying Tabular data using custom tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying Tabular data using custom tags" Watch "Displaying Tabular data using custom tags" New topic
Author

Displaying Tabular data using custom tags

jai walia
Greenhorn

Joined: Jun 24, 2008
Posts: 4
Hi everybody,

I am planning to write a custom tag which will display content in a typical tabular format plus paging and ordering.
My question is which way I should follow: Simple Tag(JSP2) or Classical Tags ? Also, I my creating the portal using MVC arch, so therefore I cannot go for JSTL db_access tag and <c:forEach> for printing as HTML table.

How can I achieve this using tags + MVC architecture?


Thanks,<br />jai_walia
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

"jai", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Why would you not use the SimpleTag support mechanisms? Is therre something you plan to dothat doesn't fit into that?

And of course you can use JSTL tags, just not the SQL tags.
Arvind Mahendra
Ranch Hand

Joined: Jul 14, 2007
Posts: 1162
you can accomplish everything you mentioned with just JSTL if you wanted.


I want to be like marc
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Not if he wants to adhere to modern best practices -- such as MVC structure. Doing SQL on a JSP, with or without JSTL, is not a recommended practice.
jai walia
Greenhorn

Joined: Jun 24, 2008
Posts: 4
Thanks Bear,Arvind for the comments.

Lets have some clear picture: There is a link [List Customers], which calls a servlet, do the processing and stores a ArrayList request attribute 'custList' and forwarded to list.jsp.

Here I can display all the emp details. but the problem is that all the static header viz. CustName,CustCity etc has to be do hardcoded in jsp, and which I really don't want.

I want some tag something like: <tisplayTable header = ".." data = ".."/>

Also I dont want to do any SQL processing in the view side (As per the MVC design).
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by jai walia:
Here I can display all the emp details. but the problem is that all the static header viz.


Jai, please use real words when posting to the ranch.

"emp" is not a word in the English language and I have no idea what "viz" means.


Great decision not to use JSTL SQL tags.
As you've said, they have no place in an application that adheres to MVC.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
jai walia
Greenhorn

Joined: Jun 24, 2008
Posts: 4
thanks ben, that was important (imp) not "emp" and viz means for example.
anyways..... ;)
Here is my small part of DAO code which return customer (cust) array list:

public static ArrayList <String> getCustomerList()
{
ArrayList <String> custList= new ArrayList();
ArrayList <String> custHeader= new ArrayList();

// DB connection code goes here ....

sql = "SELECT sCustId AS CustId,sCustName AS CustName,sCustCity AS CustCity FROM cust_master";
ResultSetMetaData meta = pStmt.getMetaData();
for(int j=1;j<=meta.getColumnCount();j++)
{
custList.add(meta.getColumnLabel(j));
}
if(totalRecords > 0)
{
while(rs.next())
{
CustomerTO custTO = new CustomerTO(); // Transfer Objects or Value Objects
custTO.setCustLoginId(rs.getString("CustId"));
custTO.setCustName(rs.getString("CustomerName"));
custTO.setCustCity(rs.getString("CustCity"));
custList.add(custTO);
}
}
return custList
}

Now I want to know how to add the metadata as a column header in the list or other collection with all customer details. In Short:

One Collection (custCollection) = Column Names + Customer Data

and in jsp by using "custCollection" I must be able to print the column headers and the customer data.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying Tabular data using custom tags