Wicket and Scala

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Wicket and Scala

danisevsky
Hello, I am playing with Scala and Wicket and I am not clear about
using "val" and "var" when I am working with JPA entity objects (which
are not serializable). For example:

    add(new RefreshingView[User]("users"){
      override def getItemModels(): java.util.Iterator[IModel[User]] = {
        var models = new java.util.ArrayList[IModel[User]]();
        for(user <- getAllUsers()){
          models.add(new EntityDetachableModel[User](user))
        }
        models.iterator()
      }
      def populateItem(item: Item[User]) = {
        val user = item.getModelObject // is this the same like final
User user = item.getModelObject() in Java?
        //...
      }
    })

if val user = item.getModelObject is the same like:
final User user = item.getModelObject
then I can't use val for entity objects because they are not
serializable and outer class (RefreshingView) holds reference on its
final fields. Is it true?
So should I use always var for non serializable objects?

Thank you in advance for clarification.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Wicket and Scala

Martin Grigorov-4
Do you experience problems ?
I see no reason this to fail.
I think the constant (val/final) should be declared outside of the
RepeatingView scope and used inside it, then it will be serialized
with it.

On Wed, Aug 24, 2011 at 10:45 AM, danisevsky <[hidden email]> wrote:

> Hello, I am playing with Scala and Wicket and I am not clear about
> using "val" and "var" when I am working with JPA entity objects (which
> are not serializable). For example:
>
>    add(new RefreshingView[User]("users"){
>      override def getItemModels(): java.util.Iterator[IModel[User]] = {
>        var models = new java.util.ArrayList[IModel[User]]();
>        for(user <- getAllUsers()){
>          models.add(new EntityDetachableModel[User](user))
>        }
>        models.iterator()
>      }
>      def populateItem(item: Item[User]) = {
>        val user = item.getModelObject // is this the same like final
> User user = item.getModelObject() in Java?
>        //...
>      }
>    })
>
> if val user = item.getModelObject is the same like:
> final User user = item.getModelObject
> then I can't use val for entity objects because they are not
> serializable and outer class (RefreshingView) holds reference on its
> final fields. Is it true?
> So should I use always var for non serializable objects?
>
> Thank you in advance for clarification.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Wicket and Scala

Bruno Borges
Define as var

I had some serialization problems with that too.



On Wed, Aug 24, 2011 at 9:55 AM, Martin Grigorov <[hidden email]>wrote:

> Do you experience problems ?
> I see no reason this to fail.
> I think the constant (val/final) should be declared outside of the
> RepeatingView scope and used inside it, then it will be serialized
> with it.
>
> On Wed, Aug 24, 2011 at 10:45 AM, danisevsky <[hidden email]> wrote:
> > Hello, I am playing with Scala and Wicket and I am not clear about
> > using "val" and "var" when I am working with JPA entity objects (which
> > are not serializable). For example:
> >
> >    add(new RefreshingView[User]("users"){
> >      override def getItemModels(): java.util.Iterator[IModel[User]] = {
> >        var models = new java.util.ArrayList[IModel[User]]();
> >        for(user <- getAllUsers()){
> >          models.add(new EntityDetachableModel[User](user))
> >        }
> >        models.iterator()
> >      }
> >      def populateItem(item: Item[User]) = {
> >        val user = item.getModelObject // is this the same like final
> > User user = item.getModelObject() in Java?
> >        //...
> >      }
> >    })
> >
> > if val user = item.getModelObject is the same like:
> > final User user = item.getModelObject
> > then I can't use val for entity objects because they are not
> > serializable and outer class (RefreshingView) holds reference on its
> > final fields. Is it true?
> > So should I use always var for non serializable objects?
> >
> > Thank you in advance for clarification.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>