Forums Register Login

How to write boolean expression from string in JSF?

+Pie Number of slices to send: Send
Hi,

I'm using JSF 1.1 with Resin 3.0.19. Is there a way to write an equalsIgnoreCase expression in JSF syntax? I want to evaluate whether the expression is equal to any form of the word "true", below ...

<h:selectBooleanCheckbox value="#{emailController.fields.addToENews}" />

The expression, 'emailController.fields.addToENews' returns a string, but the selectBooleanCheckbox requires a boolean.

Thanks for any help, - Dave
+Pie Number of slices to send: Send
Resin, Tomcat, WebLogic, doesn't matter.

In some cases, you can map Strings directly to booleans, since Java has certain conversion conventions (and I believe they're case-insensitive), but I'm assuming that that didn't work here. Besides, I've fought the same problem myself, since databases rarely support true boolean datatypes.

You can create a custom JSF converter to handle this. One side of the conversion should be Boolean, the other would be String. Which on reflection, should be a String value of "true" or "false", I think, so now I'm not so sure if you've tried the easy solution or not.
+Pie Number of slices to send: Send
Hey Dave, what exactly you are trying to get by using a string type for a checkbox. A checkbox needs a boolean so that it can flip the values on check-uncheck.
Anyways by the time you decide the correctness of the approach, answer of your question is, YES...
We can write expression to evaluate it.

<h:selectBooleanCheckbox value="#{emailController.fields.addToENews eq 'enews'}" />


Hope this helps
+Pie Number of slices to send: Send
Welcome to the JavaRanch, Abhshisk!

You forgot one minor detail. One of the differences between "#" and "$" EL expressions is that the "#" can work in 2 directions. Consider what your sample would think of an attempt to update the backing bean.
+Pie Number of slices to send: Send
You can use boolean expressions as follows

oncomplete="if(#{myObj.isSelected})Richfaces.hideModalPanel('popup1');"
+Pie Number of slices to send: Send
Thanks Tim

I understand your concern. That is the reason why I asked Dave to check his approach coz in value tag you are not supposed to evaluate expressions. This sample was just to demonstrate the use of expression language in JSF. This can be useful when your are using attributes like 'rendered' , 'disabled' etc.
Correct me if I am wrong.
+Pie Number of slices to send: Send
 

Abhishk Gupta wrote:Thanks Tim

I understand your concern. That is the reason why I asked Dave to check his approach coz in value tag you are not supposed to evaluate expressions. This sample was just to demonstrate the use of expression language in JSF. This can be useful when your are using attributes like 'rendered' , 'disabled' etc.
Correct me if I am wrong.



Oh, I've a few of those myself. But the boolean checkbox is an input/output control, which is why I mentioned the perils of using a non-lvalue expression on its "value" attribute.
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 8446 times.
Similar Threads
Expression instead of condition in if block
Assertion
Boolean type from 0 length string
Boolean Expression Evaluation Framework
tag inside other tag
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:13:23.