Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using css to change the color inside a c:if tag of JSTL

I have the following JSP code for a table

    <table>
    <c:if test="${testruns.employeecase != null}">
    <tr><th colspan="2" class="labelOnLeft">
    <label class="labelOnLeft">
    <html:checkbox name="testruns" indexed="true" property="selectedCheckbox" />
    <bean:write name="testruns" property="label" /> - <bean:write name="testruns" property="employeecase" />
    <c:if test ="${testruns.testAvailable}">Test Available </c:if></label>
    <html:hidden name="testruns"indexed="true" property="label" /></th></tr>

and I’m mainly concerned about setting the text color for the line <c: if test ="${testruns.testAvailable}">Test Available </c:if>. So if the condition is true, the text Test Available is printed on the screen and I want to do css work here, maybe inline and set the color of the text to red. How should I go about it?

I don’t want to do it on labelOnLeft class as that will apply the color to everything inside the label tag. Should I not use <c:if> tag and use something else?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the style attribute to set the color of the text inline. You can modify the <c:if> tag to include the style attribute and set its value based on the condition.

Here’s an example:

<c:if test="${testruns.testAvailable}">
  <span style="color: red;">Test Available</span>
</c:if>

In this example, if the testAvailable property of testruns is true, the text "Test Available" will be displayed in red color using the tag and the style attribute. You can adjust the color value to any color of your choice.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading