Ternary operator or simplifying what I'm using in the code
posted 7 months ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have the following code in my JSP page:
This is printing the following on the web page when the boolean value of carUsageStatus is true in the database table:
Car Used? true
I want to print Yes or No in case it is true or false. So I approached it like the following but it always prints "No" for some reason:
I also tried the following but it only prints "true" when the value is true.:
Is there anything wrong I'm doing here?
This is printing the following on the web page when the boolean value of carUsageStatus is true in the database table:
Car Used? true
I want to print Yes or No in case it is true or false. So I approached it like the following but it always prints "No" for some reason:
I also tried the following but it only prints "true" when the value is true.:
Is there anything wrong I'm doing here?
posted 7 months ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Instead, try this:
As I mentioned elsewhere that old "bean" stuff is mostly obsoleted by the Unified Expression Language (UEL).
Note that I'm assuming that the viewObject's class has a method with the signature "public boolean isCarUsageStatus()" to return that value to the JSP.
The other option would be to have a "public String getCarUsageStatus()" that returned "Yes" or "No" in which case the EL simplifies to "<tr><td>${viewObject.carUsageStatus}</td></tr>"
As I mentioned elsewhere that old "bean" stuff is mostly obsoleted by the Unified Expression Language (UEL).
Note that I'm assuming that the viewObject's class has a method with the signature "public boolean isCarUsageStatus()" to return that value to the JSP.
The other option would be to have a "public String getCarUsageStatus()" that returned "Yes" or "No" in which case the EL simplifies to "<tr><td>${viewObject.carUsageStatus}</td></tr>"
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
Jack Tauson
Ranch Hand
Posts: 495
posted 7 months ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Tim Holloway wrote:Instead, try this:
Surprisingly, this prints nothing. When I inspected the browser, I saw the following HTML:
Not sure why it's adding empty td and then another one with No below it.
posted 7 months ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Your table is malformed. TH tags should be in a TR of their own, as they are literally the top row (table header row) of the table. Which I see I forgot to do in my example.
Sorry, I haven't coded HTML at that low a level in quite a while. I also don't believe "label" is a legitimate HTML tag, and the standard for HTML is that unrecognized tags are ignored. Pretty sure that the empty "td" is your th.
Beyond that, I'd think that something is looking at/altering the raw HTML, but I can't think of what it might be.
Sorry, I haven't coded HTML at that low a level in quite a while. I also don't believe "label" is a legitimate HTML tag, and the standard for HTML is that unrecognized tags are ignored. Pretty sure that the empty "td" is your th.
Beyond that, I'd think that something is looking at/altering the raw HTML, but I can't think of what it might be.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
Jack Tauson
Ranch Hand
Posts: 495
posted 7 months ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
It's working now. I saw what was done in a similar case somewhere in the code and it looked like in Java, there was a method named booleanToString which was returning " No" when the value was null, and it was returning "Yes", when there was some value returned. I appreciate your help.
posted 7 months ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Please don't quote the whole of the preceding post; that adds nothing and is liable to removal without notice.
What did you change to make the app work?
What did you change to make the app work?
| After some pecan pie, you might want to cleanse your palatte with this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |











