• Post Reply Bookmark Topic Watch Topic
  • New Topic

protecting against empty string in property  RSS feed

 
Barry Gold
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an object called "feature" that contain various properties. One of these is a "Name" object which in turn has the properties "english" and "spanish". All this comes from a database, of course.

All features have an english name, but not all have been translated into spanish, so the "spanish" property may be empty (""). I want to output the spanish if it's present, otherwise the english.

I naively tried:
<c:choose>
<c:when <test="${empty feature.shortName.spanish}">
<c ut escapeXml="false"
value="${feature.shortName.english}"/>
</c:when>
<c therwise>
<c ut escapeXml="false"
value="${feature.shortName.spanish}"/>
</c therwise>
</c:choose>

And ended up at the errorPage. This relates to another problem I'm having, which is that I the errorPage param prevents me from seeing any compilation errors that might be coming from my page.

Any suggestions?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, what you are doing is really not the best way to internationilze an applciation. Java has a lot of mechanisms to help you with that (in which you place the translations into properties files) inlcuding the "fmt" tags of the JSTL. But that's not something you're going to fix in the next 5 minutes so...

Your error page should not be silently eating the problems. A properly constructed error page should log the problems where development staff can access them before presenting a user-friendly lipstick page to the user. Poke whoever is responsible for that page to implement that.

Short term, you can just remove the page directive until you get the page debugged.

Without the error reports, you're really behind the 8-ball in trying to develop your pages.

And finally, if you are using JSP 2.0 and JSTL 1.1, you can probably simplify that whole construct by use of the EL ternary operator (?).
[ January 31, 2006: Message edited by: Bear Bibeault ]
 
Barry Gold
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like my version of Tomcat (5.5.7) doesn't support those features.

But I have discovered that
<c:when test='${option.name.spanish == ""}'>
Does what I want.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gold:
It looks like my version of Tomcat (5.5.7) doesn't support those features.


What features?
 
Barry Gold
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, "that feature": the el ternary operator. At least, I tried it and got the whole sequence including the ternary operator.

Doesn't matter now, because I have it working right with <c\:choose>.

Now if I can just figure out why the jscript is turning my entities into \\x notation when it extracts them from the "onclick" property....

Oh well, life goes on. And so does debugging.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!