File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes setting HTML format for only one item in a JSP/EL list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "setting HTML format for only one item in a JSP/EL list" Watch "setting HTML format for only one item in a JSP/EL list" New topic
Author

setting HTML format for only one item in a JSP/EL list

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4634
    
    5

Suppose my EL contains a list such as
502/340; 502/350; 502/353

I can display this in my JSP using code such as




But instead of having them all formatted identically, I want to bold the first one, so the output looks more like


502/340; 502/350; 502/353

How can specify that I want the bold only for the first one?

And while I'm thinking, how can I get it to put the semicolon ";" only between the values, not after each one? And of course, if there is only one entry in the list, I want it bold with no following semicolon.
Thanks

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

The c:forEach element has a "varStatus" attribute which allows you to specify a variable which tells you about the status of the loop. One of the things it tells you is whether it's the first time through the loop. So (from memory) something like this:

I think the varStatus variable can also tell you if it's the last time through the loop, if that works better for getting the semicolons right. And if my memory wasn't perfect (it happens occasionally) then track down the documentation.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

The varStatus attribute allows you to create a construct that will give you information such as the loop index et al. You can use this to determine if you are on the first iteration or not and add the appropriate CSS to bold the item when appropriate.


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

Joined: Jan 10, 2002
Posts: 60046
    
  65

Paul, are you going to make a habit of this? (Posting seconds ahead of me.)










Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Though, I'd use CSS rather than the <b> tag. And likely the ? operator rather than <c:choose>.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

Bear Bibeault wrote:Paul, are you going to make a habit of this? (Posting seconds ahead of me.)


You might want to check out the webcam you just installed in your computer...
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4634
    
    5

Thanks to you both. That works great.
I'm actually using <strong> so the CSS folks can have their way with it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

Bear Bibeault wrote:Though, I'd use CSS rather than the <b> tag. And likely the ? operator rather than <c:choose>.


I probably would too if I wasn't typing as fast as possible.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Paul Clapham wrote:You might want to check out the webcam you just installed in your computer...

I just duct-taped the lens.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting HTML format for only one item in a JSP/EL list
 
Similar Threads
Display information related to that link
Embedding Lists in XHTML
Have the rules for EL in a JSP changed?
jQuery -- add remove list item
How to populate Dropdownlist from database