0

I'm a new member of stackoverflow but since this is the first problem I really can't seem to fix.

I know the question probably is unclear but here is my problem. For our backend application we use JSF. Now there is a p:selectOneMenu with selectItems that are automatically filled (DatabaseServers) but we've added a new attribute (boolean full) and my question now is if it is possible to edit the background-color of the full databases in red and the not full databases in green.

<p:outputLabel for="emrDatabaseServer"
                        value="#{msg['tenants.label.emrDatabase']}" />
                    <p:selectOneMenu id="emrDatabaseServer" style="width:250px;"
                        value="#{tenantController.entity.emrDatabaseServer}"
                        effect="fade" required="true"
                        converter="#{databaseServerConverter}">
                        <f:selectItem itemLabel="Select One" itemValue="" />
                        <f:selectItems value="#{tenantController.emrDatabaseServers}"
                            var="emrDB"
                            itemLabel="#{emrDB.name} (#{emrDB.host}:#{emrDB.port}) (#{emrDB.nbDatabases} dbs)"
                            itemValue="#{emrDB}" />
                        <p:ajax event="change"
                            listener="#{tenantController.onValueChange}" update="save" />
                    </p:selectOneMenu>

I've tried countless things but it just doesn't seem to work.

I would also like to mention that I don't have the option of using code from other packages and so.

ZigaJack
  • 1
  • 1

1 Answers1

0

Styling options of a select-element is not possible in a clean and cross-browser-compatible way, as described here.

But if you would use some hack that satisfied your styling-requirement, there is no style or styleClass attribute for <f:selectItem> resp. <f:selectItems>. For this problem you could try using a pass-through-attribute as described by this anser (which uses the title-attribute instead of style, but you got the idea).

But all in all, what you are trying to do would result in a big hack and should be avoided.

Community
  • 1
  • 1
Martin Höller
  • 2,714
  • 26
  • 44