• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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: 28469
210
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!
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic