Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL tags - write one when something, a different tag when something else  RSS feed

 
George Atkinson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to 'override' an existing JSTL tag like the following, but it isn't working since i'm mixing JSTL tags and html tags that don't match with the JSTL end tag. I have to use the <table:tr> JSTL tag since it is alternating row highlighting. Thanks for any help....


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few things:

First: please check your private messages for an important administrative matter. Thanks.

Second: there are no Struts tags in your example. Did you mean JSTL tags?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Third: please don't "ninja edit" your post (except for things like adding code tags). It makes replies made before the edit make no sense.
 
George Atkinson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Third: please don't "ninja edit" your post (except for things like adding code tags). It makes replies made before the edit make no sense.


Apologies.

I think i'm all sorted now.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Hiroshima wrote:I have to use the <table:tr> JSTL tag since it is alternating row highlighting.

<table:tr> is not a JSTL tag.

In any case, no you can't stagger custom tags like that. XML rules must be followed.
 
George Atkinson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
George Hiroshima wrote:I have to use the <table:tr> JSTL tag since it is alternating row highlighting.

<table:tr> is not a JSTL tag.

In any case, no you can't stagger custom tags like that. XML rules must be followed.


I am sorry. As I am new, I do not know the difference between a struts tag and a jstl tag. And I don't know how to code this, which is why I am posting the question here. I would like to learn. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Hiroshima wrote:I think i'm all sorted now.

So, is the problem solved or not?
 
George Atkinson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
George Hiroshima wrote:I think i'm all sorted now.

So, is the problem solved or not?


No, it is not.

When I said I am all sorted, I meant that I changed my user name.

I'm still looking for a solution.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The solution is to properly nest the tags. There is no other way. Why do you feel that you need to use improper nesting?
 
George Atkinson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The solution is to properly nest the tags. There is no other way. Why do you feel that you need to use improper nesting?


I know I can do this:



But I would like to figure out a way not to repeat the data.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's just to apply styling, use CSS rather than deprecated bgcolor.
 
George Atkinson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:If it's just to apply styling, use CSS rather than deprecated bgcolor.


I am trying to get someone to show me how to code this with JSTL so that I don't repeat the TD contents. CSS styling has nothing to do with this. <table:tr> alternates rows of shaded and white. I want to override the <table:tr> and use a particular bgcolor instead of the regular shaded and white background (that the <table:tr> produces) when that condition is met.

I want to do this WITHOUT having to repeat the same code twice.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check your private messages for an important administrative matter. Again.

George Hiroshima wrote:CSS styling has nothing to do with this.

From what you've described, it has everything to do with this. If all you want to affect is the styling of the rows, CSS is the right way to do it. bgcolor is deprecated and the wrong way to do it.

Moreover, for just small adjustments to markup, you'd be better off with the EL ternary operator than heavy-weight JSTL conditionals.

I want to do this WITHOUT having to repeat the same code twice.


I repeat, CSS.

 
George Atkinson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think an EL ternary would work great if there were only two variables occurring here. The issue is that the <table:tr> tag does a ternary operation in the java file to display the tag as alternating <table bgcolor="grey"> or <table bgcolor="white">. I am trying to add a third variable into the mix that if this condition, then override with <table bgcolor="someOtherColor" >.

I'd appreciate an example if you could do it.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying that the <tr:table> tag is emitting deprecated HTML?

If so, I'd dump it pretty fast. But basically, if the tag isn't doing what you want, why use it? Trying to over-complicate a JSP to make up for short-comings in a tagset is a step in the wrong direction.

Styling elements any way you want is a breeze with CSS. There's a good reason that abominations such as bgcolor are deprecated.

(P.S. You could also use JavaScript to massage the elements at load-time -- but that has its own set of headaches.)
 
George Atkinson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Are you saying that the <tr:table> tag is emitting deprecated HTML?

If so, I'd dump it pretty fast. But basically, if the tag isn't doing what you want, why use it? Trying to over-complicate a JSP to make up for short-comings in a tagset is a step in the wrong direction.

Styling elements any way you want is a breeze with CSS. There's a good reason that abominations such as bgcolor are deprecated.

(P.S. You could also use JavaScript to massage the elements at load-time -- but that has its own set of headaches.)


Bear, apologies if this is coming off as rude, but you have totally missed by a long shot what I have asked for in this thread, irrespective of using CSS.

Luckily, I found useful help in another forum.

Take care.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad that you found a solution. I hope it's not a band-aid that'll bite you later on.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just for completeness here is the basic outline of the solution offered elsewhere:

Minimal change:



A potentially better solution:


Its not exactly what was specified, as it uses the <tr> tag both times, whereas the OP had one <tr> tag, and one <table:tr> tag in the example.

I would agree with Bear that CSS should be a part of this solution.
I would envision the custom tag emitting code like the following:



You then define the oddLine/evenLine style classes in an imported css stylesheet.
If you wanted to change one of the line colours, you only have to change that css import, and you're done :-)

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or even simpler:


Why developers like to over-complicate things that are basically simple is beyond me.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!