Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set bean value to empty or null if the property is not provided?

 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thanks for reviewing my post. I've created a bean using a value from the system properties. If the system property value is not provided, I would like to handle that in the Java code. Is it possible to do this?

Using
Spring 2.5
Java 5.0
JBoss 5.1

Thank you in advance for your help.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always set properties to default values directly in your code.



Mark
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Sorry about the delay in responding. Thanks for responding to my post and your solution. Yes, your solution would definitely work if I didn't have a typo in my post...I was actually looking to see if I omit the key/value from the system properties, if I could have the bean check for a null key/value pair before setting the bean property value. I couldn't get the app to run without the key, so to work around this, I'm setting the key to an empty string. If you have another solution, I would appreciate it.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic