File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pat Farrell
Rancher
Posts: 4660
5
Linux Mac OS X VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, are you going to make a habit of this? (Posting seconds ahead of me.)










 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though, I'd use CSS rather than the <b> tag. And likely the ? operator rather than <c:choose>.
 
Paul Clapham
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4660
5
Linux Mac OS X VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to you both. That works great.
I'm actually using <strong> so the CSS folks can have their way with it.
 
Paul Clapham
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:You might want to check out the webcam you just installed in your computer...

I just duct-taped the lens.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic