Best way to do a choose without having to repeat the data?

This is probably an easy one that I am just missing.
Very rusty.
I am trying to figure out 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.
I probably need to do some sort of c:set using a variable but i'm not sure how.
<c:choose>
<c:when test="${Form.formFieldId == "xyx"}">
     <tr bgcolor="#344543" >
TD1
TD2
TD3
</tr>
</c:when>
<c:otherwise>
     <table:tr>
SAME TD1 as above
SAME TD2 as above
SAME TD3 as above
</table:tr>
</c:otherwise>
</c:choose>
Thanks for any help.

Here is one way:
<c:set var="tdContent">
TD1
TD2
TD3
</c:set>
<c:choose>
<c:when test="${Form.formFieldId == "xyx"}">
<tr bgcolor="#344543" >
  ${tdContent}
</tr>
</c:when>
<c:otherwise>
<table:tr>
  ${tdContent}
</table:tr>
</c:otherwise>
</c:choose>You could also potentially do the following
<c:set var="bgColorAttribute" value="${Form.formFieldId == 'xyx' ? '' : ' bgcolor="#344543"'} "/>
<tr ${bgColorAttribute}>
TD1
TD2
TD3
</tr>Its not exactly what you were after, as it uses the <tr> tag both times, whereas you had one <tr> tag, and one <table:tr> tag in your example.
What is the <table:tr> tag? Its not one I am familiar with. Is it a standard tag library? Or a custom one you are using?
Can you share that taglib import with us so we can see what tag library you are using?
eg for the JSTL core library the line is: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
For the table taglib it should be something like: <%@ taglib prefix="table" uri="??????" %>
You say CSS styling has nothing to do with this. It probably should
What you would really want is something like
<tr class="oddLine">
<tr class="evenLine">and then define the oddLine/evenLine style classes in an imported css stylesheet.
Then if you wanted to change one of the line colours, you only have to change that css import, and you're done :-)
cheers,
evnafets

Similar Messages

Maybe you are looking for

  • IMovie 8.0.5 doesn't recognize Firewire Camcorder

    ...but iMovie 6.0.3 does. I'm using both versions of iMovie because of my 3rd party plugins which stopped working in newer iMovie versions. SystemProfiler shows camera, I tried different accounts with same results.

  • Extract Text from PostScript

    Can anyone please tell me how to extract text from postscript

  • How to make script depended on specific network???

    I hope that someone can help me with this. I do not yet have much experience with scripting, but I made a script which connects my macbook to a folder on my NAS. However, if my local network is not available the script will hang itself waiting until

  • Can't Export to .mov

    I'm attempting to Export using Export > Quicktime Movie... It only gives me the option to Include Audio & Video, Audio or Video Only, Markers and whether or not to create a Self-Contained Movie... Whenever I hit Save, it creates a Final Cut Express M

  • Ipod Touch (2g) Transfer Issues

    I'm on Windows 7 RTM, when it comes to moving content from my PC to my IPod I have no issues, everything transfers just fine. When transferring content from my ipod to my pc however, there are constant issues with the transfer freezing and what appea