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

bean:write

 
Eric Sexton
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp that has several address lines like this:

There are 3 address lines, but sometimes address lines 2 and 3 are blank. I don't want to write out blank lines if they are blank. What is the best way to go about this formatting?
 
Bernardus Irmanto
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U can use the evaluation logic tag for that case. I think logic:notEqual will do.
<logic:notEqual value="" name="GeneralInfo" property="address2">
<bean:write ...
</logic:notEqual>
rgds
beN
 
Eric Sexton
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not at work right now, so I can't test this out. But I wanted to ask, should I leave the value parameter blank? I did try the logic tag, but could not get it to work. I did not try it exactly as you specified though. Thanks for the help.
 
Bernardus Irmanto
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use the logic:notEqual(/logic:equal) tag, you must specify the value property. Yes, you can fill the value with "".
however, this tag will not work if the value of the address2 is null(it will output the following error message "Cannot compare null variable to value", just like if you compare a variable with a string value, and the var is the left operator, and it is null), so you have to make sure that your address property is not null
<logic:notEqual value="" name="GeneralInfo" property="address2">
...
</logic:notEqual>

rgds
beN
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively you can use the <logic:notEmpty> tag, which will only evaluate the nested content of the tag if the property you use is not null and not a String with a length of 0.
Here is a link to the API reference for the tag.
<logic:notEmpty>
 
Eric Sexton
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks beN.
[ October 24, 2003: Message edited by: Eric Sexton ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic