• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a conditional boolean variable  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to java and this seems like it has to be really simple, but so far I am unsuccessful. I want to create a boolean value if a certain condition is met. I need my application to compare who is logged in to my web app with the value for who created a particular report.

I retrieve the creator of a report in report.getCreatedBy() and I can display the current user with user.getName(). I need my application to determine if the person logged in is the same as the createdBy value and then set isAuthor() = true

Then I want to user the isAuthor true or false to display certain information in my jsp. That part I can handle, just not sure what I am missing / have incorrect from above.

Anyway, thanks in advance.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jason, welcome to the Ranch!

There doesn't seem anything obviously wrong with that. If it isn't working, what problems are you seeing?

Though there is a simpler way of expressing it:
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ponder:

[Edit: ewww, beat by a few seconds!]

P.S. Hopefully you are not putting Java code in your JSP!
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

The old Sun conventions are still to be found on the web. They are called archival but I think it would have been better had they updated the document. It has a page in about simpler ways to write expressions. Try here and look for §10.5.2.
 
jason thompson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick responses.

So yeah:



Works great and I was going to put this in the servlet, but I need to pass it to the jsp. Not exactly sure how to do that. How do I create a session bean from the above to pass into the jsp? Can anyone point me to a good example.

Thanks again.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That isAuthor thing looks good
you should probably verify that user is not null and that getName never returns null otherwise you will suffer a NullPointerException.

Don't know about the JSP. I shall try duplicating this discussion in the JSP forum in the hope of getting you more attention.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!