aspose file tools*
The moose likes JSP and the fly likes Ordered List tag inside jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Ordered List tag inside jsp" Watch "Ordered List tag inside jsp" New topic
Author

Ordered List tag inside jsp

koshan koshaa
Greenhorn

Joined: Jul 05, 2010
Posts: 2
As you can see below I am displaying some employee details using JSP embeded with html tags,
I tried to use html <OL> (ordered list) tag to display the details in ordered way but it not working.

Do i make any mistake or is there any other way?

thanks in advance, sorry if i ask about html in JSP forum!!



Vicky Vijay
Ranch Hand

Joined: Apr 23, 2008
Posts: 125
Hello,

Refer the below link


HTML Ordered list inside table - 1


HTML Ordered list inside table - 2
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

you have table. and what you are trying to accomplish by using ol tag with this table?...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch koshan! :)

and Please use code tag while posting your code. this time i have added them for you!
koshan koshaa
Greenhorn

Joined: Jul 05, 2010
Posts: 2
actually i m getting these data from 3 tables using join(sql) operation, but i want to display the row numbers each time i fetch the data from DB,

the row numbers are incremental as it comes from DB, I think this problem can't be solved using HTML.

How to do it using Java Programming logic ?

to display row numbers of the table and increment the row numbers each time the data is fetched from DB.

any help will be appreciated, thanks

[Edit: removed there all-bold text. Please reserve bold for emphasis only.]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Instead of:

use


it is equivalent, but better :-)
The whole point of jsp is NOT to use java code if at all possible.

This page would benefit from using JSTL rather than scriptlet code, though its not as bad as some I've seen :-)

I don't think list tags and table tags interact very well. Choose one or the other to display what you want.

The structure of a list in html should be <ol><li><li><li></ol>
Your <ol> tags should thus be outside of your loop, and each record in the list should be a <li>
Or
Your <table> tags should be outside of your loop, and each record in the list should be a <tr>

You want to display the current row number on each iteration? Use a variable to keep count (increment by on on each iteration of the loop) or even better, use that JSTL forEach tag and the varStatus attribute.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

It seems that you are working backwards. First, figure out what the valid HTML that you want to display is, then make a JSP that emits that HTML.

And as Stefan pointed out, you should be using JSTL and EL in place of Java scriptlets. Java scriptlets have been outdated and discredited for 10 years now. 10 years! It's time to bring your JSP knowledge out of the dark ages.


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

Joined: Apr 16, 2008
Posts: 2187
Alternatively, if you need to create a very complex HTML table based on a very complex object data model and if it seems to exceed the capabilities of JSTL or EL, you should create the HTML table in a custom Java Servlet rather than a Java Server Page.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

I see no way in which emitting HTML in a servlet is easier than using a JSP. Much harder, and certainly messier, in fact.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
My post was based on an alternative, not necessarily the what the OP is speaking on. My statements below are about a different type of requirement for a HTML table.

In order to see why it would be better, you would need to also understand the specific complex table requirements and also the specific complex object model. Without this information, it would be very difficult to understand. JSP is not the better option here. Having this type of code in a well-written Servlet class is cleaner and it is easier to understand. The alternative would be a messy mixture of HTML tags and scriptlets in a JSP (much harder to maintain or teach.)

A very complex HTML should be crafted with servlet code. This is a case where the complexity of the requirements and data model surpass the functionality of simple tag libraries of JSTL. JSTL encapsulate "common" functionality. The type of table I'm referring to is not common and the relationships between data is complex. Think multiple iterations of multiple Collections and multiple Maps with nested Lists combined with the required serialized writing of a HTML table, i.e. left to right, row by row.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

You have no chance of convincing me that complex HTML is better built up with strings inside Java code than with templating tools. But use whatever works best for you.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Granted that jsp/jtsl can not handle the most complex html you can imagine.

However given that scenario, I can give you two other possible solutions
- use java code to produce a simpler data structure that can be displayed easily on a JSP.
- use a JSP custom tag to handle the display of this complex component, and abstract the complexity away.

it would be a very rare case where I would see the need to have out.println("<html tags>") in a servlet ever again.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Stefan Evans wrote:- use java code to produce a simpler data structure that can be displayed easily on a JSP.

Ding.Ding.Ding. Give the man a cigar.

Resorting to servlets to generate markup is the last thing to try to do. If you are having trouble consuming a data construct in the JSP, the fault is with the construct, not with JSP.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
- use java code to produce a simpler data structure that can be displayed easily on a JSP.

If this is possible, it certainly is better than scriptlets in JSP or a custom servlet. However, in reality it is possible that such a "simpler" data structure cannot be created. In my example, we are already creating a simplified Presentation data object model from a Storage data object model. The simplified one is still very complex and exceeds the functionality of public tag libraries.

- use a JSP custom tag to handle the display of this complex component, and abstract the complexity away.


This is an option. To handle the complexity mentioned however would require multiple tags, and to get them all to work together would actually be adding complexity, not taking it away. Adding complexity to simply implement a different design is not a good decision, in my opinion. Also, since the tags would never be able to be "reused" in any other type of context, there is little justification for creating a special JSP tag library. Moving the complexity to a tag library is not removing it, it simply is "moving" it and in this case adding extra layers of complexity uneccessarily.

Resorting to servlets to generate markup is the last thing to try to do


True. This would be the last option. It still is an option though. And when that table is generated and viewed in the browser, the customer really doesn't care about how the HTML table was created. The business intelligence derived from the information displayed in the table is the most important thing. Java Servlet imlementations can be very powerful and help realize things that were thought to be not possible.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Jimmy Clark wrote:it certainly is better than scriptlets in JSP

Hearty agreement! Anything is better than scriptlets in a JSP.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Ordered List tag inside jsp