You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by danisevsky <da...@gmail.com> on 2011/08/24 09:45:34 UTC
Wicket and Scala
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket and Scala
Posted by Bruno Borges <br...@gmail.com>.
Define as var
I had some serialization problems with that too.
On Wed, Aug 24, 2011 at 9:55 AM, Martin Grigorov <mg...@apache.org>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 <da...@gmail.com> 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: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Wicket and Scala
Posted by Martin Grigorov <mg...@apache.org>.
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 <da...@gmail.com> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org