Hi,

keep it simple, use the definition: 
  "$! is used to supress reporting an error if it does not 
   have a value replacing it for the empty value (null for 
   a set, empty string for a render)."

Remember the #invoke macro discussion to call a (bean) method 
and ingore any return value. so it was sugested to do something
like:
  #macro( call $foo )#set( $dummy = $foo )#end
  ## then
  #call( $bar.method("woobie") )
which would bark if it would evaluate to null or if it does
not have a return value. I found another solution for this:
  #macro( call $foo )#if( $foo )#**##end#end

I also presented a *real* usage of it as for example caching
a JDOM-loaded XML file in the session:
  ## in next line I don't want it to bark if it is not yet cached!  
  #set( $foo = $!data.Session.getAttribute("cachedXML") )
  #if( !$foo )
    ## if it was not cached, load it here...
    #set( $foo = $Xml.load("complex/file.xml") )
    ## cache it (ignore whatever the return value of setAttribute() is)
    #call( $data.Session.setAttribute("cachedXML", $foo) )
  #end

"Geir Magnusson Jr." wrote:
> 
> I see what you are saying, and I understand what you need.
> 
> But I wonder if we are misusing the $! as that says 'don't render the
> literal if not in the context'.

I see it more like 'don't report any errors if it does not have a value
and use the empty value (null for a set, empty string for a render)'.

> 
> So do we want:
> 
> 1) Status quo : don't do anything and use the logging switch?  Christoph
> has a point that it isn't enough.

Would do some disturbing logs which cannot be easily be differentiated
to real problem logs.

> 
> 2) Make it :
>    #set ($foo = $!splarg )
>   as Christoph suggests

Yup.

> 
> 3)  Make it :
> 
>    #set ( $!foo = $splarg )
> 
>   because you are saying don't log if the assignment to $foo is null

This would just as well do it! It could also solve the problem of:
  #set ( $!foo = $notAnInteger + 1 )
But I believe this is a place where $! does not make sense (the 
designer should not use it, and therefore gets a log message).

> 
> 4) something else?
> 
> geir

:) Christoph

Reply via email to