2

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
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Thang Pham
  • 38,125
  • 75
  • 201
  • 285

1 Answers1

6

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
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Also; a few components have the attribute disabled, used the same way. I would suggest keeping a boolean variable for enabled/disabled, though: `` – Tormod Aug 17 '10 at 21:24
  • The components representing HTML form elements indeed have that. But that was not *that* obvious from the question. – BalusC Aug 17 '10 at 21:28
  • 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 – Thang Pham Aug 17 '10 at 21:56
  • 1
    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 Aug 18 '10 at 01:57