• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Check NULL in JSTL

 
Greenhorn
Posts: 15
Mac Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm developing a JSF application and at some point in a jsp I need to show one of three possible values of an object, that is:

myObject
+--- subObject1
+--- subObject2
+--- property1

if subObject1 is not null I print subObject1.description, if it's null I check for subObject2, if it's not null I print subObject2.description, otherwhise I print property1

I have this piece of code:


Any ideas?? Should I check with "myObject.subObject != null"??
 
Ranch Hand
Posts: 90
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch Maria!!

Sure you use myObject.subObject ne null (ne is the same that !=) or use not empty, both do the same, but I think you are putting business logic in your view, I suggest you because your're using JSF (And JSF is based in the Model-View-Controller pattern) you should put your bussiness logic in your model, but this is just a suggestion. For example you can check the same in your bean and show the result in your view, for example:
And in your view use
Regards
Cesar
 
Maria Diminuta
Greenhorn
Posts: 15
Mac Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cesar Loachamin wrote:Welcome to JavaRanch Maria!!


Hehe thanks!!

Cesar Loachamin wrote: but I think you are putting business logic in your view, I suggest you because your're using JSF (And JSF is based in the Model-View-Controller pattern) you should put your bussiness logic in your model, but this is just a suggestion.



I do think the same, but the guy who is managing this project told me to do this way because he doesn't want the java class to be modified from now on... I think it's kind of weird but... he's the boss...


Could it be that it doesn't work because myObject is part of an iteration of objects as follows:

 
Maria Diminuta
Greenhorn
Posts: 15
Mac Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I forgot the most important thing... the piece of code I posted doesn't work, that's why I posted it, but forgot to tell that it doesn't work
 
Saloon Keeper
Posts: 27879
197
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
Ick. Lose the JSTL. You don't need it and it only causes problems. To conditionally hide an outputText, all that's required is the following extra attribute on the outputText element:


Although this is redundant, since empty text won't show up anyway, even if it's null!
 
Maria Diminuta
Greenhorn
Posts: 15
Mac Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, that's the way I solved it... the thing is that I had to check if the object was null because I need to print one of its properties, so if I just write:



it could throw an exception when subObject is null...

Thanks!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic