views:

51

answers:

1

I am using JSF 2.0 btw
I have an attribute X type Integer, that has default value 0. In my JSF page, I create a component that I want it to be disabled if X is 0, and enabled otherwise.

<h:selectBooleanCheckbox disabled="#{X}"/>

and I got this error

Cannot convert 0 of type class java.lang.Integer to class java.lang.Boolean
+3  A: 

Your question is pretty vague and ambiguous. I don't see how a converter is useful here. A converter is mere to convert between a non-standard type and String type (the standard types for which EL has builtin conversions (coercions) are primitives, Number and Boolean). Also, I think that you actually meant "rendered in component tree" when you said "disabled" and "enabled".

In a nut, you basically want <h:someComponent rendered="#{X != 0}" />.

Can't you just do that?

BalusC
I see your crystal ball is working fine today :) +1
Bozho
Also; a few components have the attribute disabled, used the same way.I would suggest keeping a boolean variable for enabled/disabled, though: `<h:commandButton disabled="#{not entityBean.enabledButton}" />`
Tormod
The components representing HTML form elements indeed have that. But that was not *that* obvious from the question.
BalusC
Sorry, I did not know you can do it like that, I originally have it as `rendered=#{X}` and hoping that it would behave like `C` where anything 0 is false, and true otherwise. But it gives me an error, said that it cant convert from 0 to type boolean, so I thought I need some kind of custom converter here. It works great now, thank you very much
Harry Pham
You're welcome. For another examples of boolean expressions in EL see [this answer](http://stackoverflow.com/questions/3466289/how-to-enable-disable-components-in-jsf-icefaces/3466918#3466918).
BalusC