jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-287

$!{text} toString()'s to "" instead of null

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.5
  • Component/s: None
  • Labels:
    None

Description

For GroovyTemplates its not very desirable to have alot of "null" printed everywhere we might have included a possible null value. So it would be nice to have a way to make GString print "" instead of null.

Velocity does that via $!{text} which I think is ok, but we may just parse the Template text and always "insert" ${(text == null) ? "" : text"} since I think its always the desired behaviour for gstrings to not print null (within Templates).

Issue Links

duplicates

Improvement - An improvement or enhancement to an existing feature or task. GROOVY-481 Consider enhancing default string templates to support $foo or $!{foo}

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.
is depended upon by

Task - A task that needs to be done. GROOVY-753 complete parser

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Yuri Schimke added a comment - 17/Mar/04 7:44 AM

What about just making it such that GroovyTemplates (possibly optionally) don't print nulls.

Its very amateurish when websites print nulls all over the place.

Especially with the null safe method invocations, it would be nice to be able to use.

${user->lastLogin}

Another thought, would be to use an OR, since this will let you give an alternative.

${user->lastLogin || "Never Logged In"}

But I don't think this will work, since || quite rightly is a boolean expression, even though "if (a)" works.

1> print (a || "b")
2> execute
true

Show
Yuri Schimke added a comment - 17/Mar/04 7:44 AM What about just making it such that GroovyTemplates (possibly optionally) don't print nulls. Its very amateurish when websites print nulls all over the place. Especially with the null safe method invocations, it would be nice to be able to use. ${user->lastLogin} Another thought, would be to use an OR, since this will let you give an alternative. ${user->lastLogin || "Never Logged In"} But I don't think this will work, since || quite rightly is a boolean expression, even though "if (a)" works. 1> print (a || "b") 2> execute true
Hide
Permalink
james strachan added a comment - 17/May/04 2:29 PM

Maybe use the ?: notation.

println "Hello there ${user ?: "uknown user"} how are you doing?"

Show
james strachan added a comment - 17/May/04 2:29 PM Maybe use the ?: notation. println "Hello there ${user ?: "uknown user"} how are you doing?"
Hide
Permalink
james strachan added a comment - 14/Jul/04 7:29 AM

Velocity uses the nice notation that if you don't wanna print nulls then you do

$!foo

which I like.

Also if we wanna handle printing of things with defaults, we should support

defaultValue = "anonymous"
println "hello ${foo || defaultValue} there"

Using the || operator to allow nulls to be handled in a more graceful way

Show
james strachan added a comment - 14/Jul/04 7:29 AM Velocity uses the nice notation that if you don't wanna print nulls then you do $!foo which I like. Also if we wanna handle printing of things with defaults, we should support defaultValue = "anonymous" println "hello ${foo || defaultValue} there" Using the || operator to allow nulls to be handled in a more graceful way
Hide
Permalink
Paul King added a comment - 30/Nov/07 8:49 PM

I believe this is now covered by:

def user
assert "Hello ${user ?: "unknown user"}, how are you?" == 'Hello unknown user, how are you?'
user = "Paul"
assert "Hello ${user ?: "unknown user"}, how are you?" == 'Hello Paul, how are you?'

Please reopen if you believe further enhancement is required.

Show
Paul King added a comment - 30/Nov/07 8:49 PM I believe this is now covered by:
def user
assert "Hello ${user ?: "unknown user"}, how are you?" == 'Hello unknown user, how are you?'
user = "Paul"
assert "Hello ${user ?: "unknown user"}, how are you?" == 'Hello Paul, how are you?'
Please reopen if you believe further enhancement is required.

People

  • Assignee:
    Paul King
    Reporter:
    Thomas Heller
Vote (0)
Watch (2)

Dates

  • Created:
    16/Mar/04 8:41 PM
    Updated:
    30/Nov/07 8:49 PM
    Resolved:
    30/Nov/07 8:49 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.