3 Replies Latest reply on Nov 28, 2016 4:35 AM by asimshaikh1

    Change Text Color depending upon text

    asimshaikh1

      Hello Everyone.

      Could anyone told me how could I apply multiple conditions to h:outputText.

       

      example. if Text is AAA then Color="red" ,  if Text is BBB then Color="green" if Text is CCC then Color="blue"

       

       

      Below code runs perfect for single condition. I wanted to add more conditions to it.

       

      <rich:column style="width:8%;">

      <f:facet name="header">#{lbl['label.eventstatus']}</f:facet>

         <h:outputText value="#{event.eventStatusDesc}"  

         style="#{event.eventStatusDesc eq 'Completed' ? 'color: red;font-weight: bold;':'color: black;'}" />

      <h:outputText value="    "/>

        <h:outputText value="#{event.resheduleDateString}"/>

          </rich:column>

        • 1. Re: Change Text Color depending upon text
          asimshaikh1

          more precisely add third condition to EL expression.

          <h:outputText value="#{event.eventStatusDesc}" 

             style="#{event.eventStatusDesc eq 'Completed' ? 'color: red;font-weight: bold;':'color: black;'}" />

          • 2. Re: Change Text Color depending upon text
            michpetrov

            Since you're using a variable from a bean why not figure out the style in the bean as well? Or you could just use CSS classes with name derived from the string you're displaying. If you really want to use EL you can nest the conditions but that's going to be confusing to work with.

            • 3. Re: Change Text Color depending upon text
              asimshaikh1

              Thank you again. The issue has been resolved by below code. Its just syntax that I am missing.

               

              style="#{event.eventStatusDesc eq 'Completed' ? 'color: green;font-weight: bold;' : (event.eventStatusDesc eq 'Rescheduled till Further Notice' ? 'color: blue;font-weight: bold;' : 'color: black;')