1

How to set colour for selectOneMenu in primefaces ?

 <p:selectOneMenu id="col" value="#{projectsController.selected.listColor}">
                    <f:selectItem itemLabel="Activity" itemValue="1"  class="redBackGroundColor"/>
                    <f:selectItem itemLabel="Activity1" itemValue="2" class="blueBackGroundColor"/>
                    <f:selectItem itemLabel="Activity2" itemValue="3" class="greenBackGroundColor"/>

                </p:selectOneMenu>

And here is my css

.redBackGroundColor{
    background-color:red;        
}

(and ofcourse for blue and green..) But it doesnt affect behavior of primeface.

helloWorld
  • 315
  • 3
  • 17
  • 1
    It seems there is a workaround in PrimeFaces 4.0. Maybe this is still valid: http://stackoverflow.com/questions/19403631/different-colors-of-options-in-selectonemenu-primefaces – LarsBauer May 11 '15 at 16:07
  • It's not a workaround but the PrimeFaces advanced way of displaying this and still valid. See http://www.primefaces.org/showcase/ui/input/oneMenu.xhtml – Kukeltje May 11 '15 at 16:22

1 Answers1

0

it's impossible in JSP but you can do that in javascript

for example :

      $(this).children("tbody").children("tr").each(function () {
              if ($(this).children("td").children("input").val() == 1) {
                       $(this).addClass("redBackGroundColor");
                } 

..... It's work for me.

Zakaria.dem
  • 293
  • 5
  • 10
  • Imo this, is a bad complex workaround compared to the 'advanced' display of selectItems in selectOneMenu – Kukeltje Feb 06 '16 at 17:45