Java object i use in scala are getting created several times -
i work play framework 2.5 , use several java classes trough scala in templates. create object 1 times
@import myclass; @foo = @{new myclass(bar)}
with code, contructor of myclass not called (i have put debug output in constructor check call of it)
now use function of java class like
@foo.getmesomebar()
somewhere in template. now, constructor called. problem: every time use function of class in same template, constructor called.
the same problem occurs, if pass scala variable template like
@othertemplate(foo)
every time foo used in othertemplate constructor called.
is desired behavior? if yes, why? if no, how can avoid it?
edit: if create myclass object in controller , pass there templates constructor called 1 times. in cases if have create myclass in template or have change lot of classes.
according documentation, should not use @foo = @{ ... }
define reusable value. preferred way do
@defining(new myclass(bar)) { foo => @foo.getmesomebar() ... @othertemplate(foo) }
your way may have unexpected results, such re-running code in block every time called.
Comments
Post a Comment