• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Ternary operator or simplifying what I'm using in the code

 
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 28997
214
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>"
 
Jack Tauson
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Tim Holloway
Saloon Keeper
Posts: 28997
214
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jack Tauson
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 81607
593
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
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
reply
    Bookmark Topic Watch Topic
  • New Topic