In a combobox I'm getting my values with : @Unique(@DbColumn(@DbName(),"Products",4));
When the value of 1 appears in column 5 of this view "Products" I would like to apply the css active (for that line) else I would like to apply the css nonactive (for that line)
Asked
Active
Viewed 287 times
0

Marc Jonkers
- 496
- 1
- 7
- 17
-
A bit more information, where do you want to set the CSS to active/unactive - `class` of combo box or some other text? – Naveen Apr 24 '13 at 09:29
-
I don't know if it's possible . I would like to set it line by line (in function of the values) for the combobox. – Marc Jonkers Apr 24 '13 at 09:52
-
You mean on the ` – Naveen Apr 24 '13 at 09:57
-
yes that's what I mean and nonactive is "text-decoration: line-through;" in my css – Marc Jonkers Apr 24 '13 at 10:06
-
2This is possible with a custom renderer... but why would you want to allow user selection of options that aren't valid? – Tim Tripcony Apr 24 '13 at 10:20
-
I don't think `style` attribute is supported on ` – Naveen Apr 24 '13 at 10:25
-
Also if you really want to show invalid values in combo box then you can set the `disabled` attribute in ` – Naveen Apr 24 '13 at 10:28
-
The user will still be able to select the product in this case. The idea is that the user can see that the product isn't sold anymore but he can still get some information about it like orderinformation for spareparts etc . – Marc Jonkers Apr 24 '13 at 11:06
1 Answers
1
All the items added to combo box belong to class javax.faces.model.SelectItem
. I don't think style
attribute is supported on <option>
tag (link). But you can set disabled
attribute. For that you can add a formula item in your combo box with below code:
var items = new Array();
var values = @Unique(@DbColumn(@DbName(),"Products",4)); // Your list of values
for (var i=0 ; i<values.length ; i++) {
items[i] = new javax.faces.model.SelectItem(values[i], values[i]);
if (values[i] == "1") { // If value is one then disable it
items[i].setDisabled(true);
}
}
return items;
This would render a disabled option in the combo box on web page which cannot be selected but would be visible.
Update:
If you want the options to be selected then you can add, say asterisk, at beginning of text to indicate that. So your code would be something like:
var items = new Array();
var values = @Unique(@DbColumn(@DbName(),"Products",4)); // Your list of values
for (var i=0 ; i<values.length ; i++) {
items[i] = new javax.faces.model.SelectItem(values[i], (values[i] == "1" ? "* " : "") + values[i]);
}
return items;

Naveen
- 6,786
- 10
- 37
- 85
-
As mentioned above , the idea is that the user can still select the non active products in order to retrieve some information about it for example to order spare parts. My idea was to draw the attention by using line trough. This doesn't seem to be possible. Is their a way to put an icon before a line in a combobox in function of the value ? This could also be a possibility. – Marc Jonkers Apr 24 '13 at 12:27
-