You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Adam Zimowski <zi...@gmail.com> on 2008/03/25 22:49:08 UTC

[T5] Inner Enums of Pages and Components

If Page or Component defines Enum internally, Tapestry throws a
ClassCastException the moment said page or component  class (or even
the template) is "hot" reloaded due to any kind of change.

Can this be fixed/change to allow inner Enums?

-adam
as of 5.0.11

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Inner Enums of Pages and Components

Posted by Davor Hrg <hr...@gmail.com>.
An idea:
I belive it has many pitfalls :(, but might be useful an idea,

tapestry could for example extend such enum (persist worker might trigger
it)
and add serialization code to it. Then when reloading it could force
serializing enum values, plus if the value gets serialized outside tapestry
it could be better handled (if servlet container serializes it).

this might only help enums..

On Tue, Mar 25, 2008 at 10:57 PM, Howard Lewis Ship <hl...@gmail.com>
wrote:

> I'm kind of surprised about that;  are you storing the enum values
> outside of the page instance (i.e. in the session?)
>
> Inner classes are loaded by the disposable component class loader (the
> class loader that handles retry logic and class transformation).  When
> a class changes, the class loader, plus and objects instantiated from
> that class loader, are discarded.
>
> If you place such an object in the session, it will hang around
> (keeping the class loader from being garbage collected) ... AND when
> the stored value is assigned to a field of the newly loaded page
> instance, it will fail with a ClassCastException because there's a new
> class (with the same name) loaded by a new class loader.
>
> I'd love to patch up these "leaky abstractions" a bit better, but
> that's partt of the price of running in your choice of servlet
> container; short of Tapestry being an application server, and not an
> application framework, it doesn't have sufficient control of things to
> make it any more seamless.
>
> On Tue, Mar 25, 2008 at 2:49 PM, Adam Zimowski <zi...@gmail.com>
> wrote:
> > If Page or Component defines Enum internally, Tapestry throws a
> >  ClassCastException the moment said page or component  class (or even
> >  the template) is "hot" reloaded due to any kind of change.
> >
> >  Can this be fixed/change to allow inner Enums?
> >
> >  -adam
> >  as of 5.0.11
> >
> >  ---------------------------------------------------------------------
> >  To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >  For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator Apache Tapestry and Apache HiveMind
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: [T5] Inner Enums of Pages and Components

Posted by Adam Zimowski <zi...@gmail.com>.
That makes totally perfect sense, and yes, I am storing an enum value
in session. So I had enum defined internally in the page, and then
@Persist on its value...  I understand the limitation, and I can only
image what cool things could be accomplished if Tapestry was budnled
with embedded Jetty....

public class AddBaseItemArticle {

 @Persist
 private DisplayMode _displayMode = DisplayMode.Fresh;

 /**
  * Represents modes in which page can be rendered. If page is entered
  * directly, or if it is reset, display mode is {@link DisplayMode#Fresh}.
  * If after fresh input block has been validated and article information
  * is being collected, the mode is {@link DisplayMode#BlockValidated}. If
  * another page referred block input (create new block for a known base
  * item), then display mode is {@link DisplayMode#DefineBlock}. Finally,
  * if another page referred article input (which requires fully defined
  * block input), display mode is {@link DisplayMode#DefineArticle}.
  *
  * @author Adam Zimowski
  */
 public enum DisplayMode {
	 Fresh, BlockValidated, DefineBlock, DefineArticle
 }

 void setDisplayMode(DisplayMode aDisplayMode) {
	_displayMode = aDisplayMode;
 }

}

On Tue, Mar 25, 2008 at 4:57 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
> I'm kind of surprised about that;  are you storing the enum values
>  outside of the page instance (i.e. in the session?)
>
>  Inner classes are loaded by the disposable component class loader (the
>  class loader that handles retry logic and class transformation).  When
>  a class changes, the class loader, plus and objects instantiated from
>  that class loader, are discarded.
>
>  If you place such an object in the session, it will hang around
>  (keeping the class loader from being garbage collected) ... AND when
>  the stored value is assigned to a field of the newly loaded page
>  instance, it will fail with a ClassCastException because there's a new
>  class (with the same name) loaded by a new class loader.
>
>  I'd love to patch up these "leaky abstractions" a bit better, but
>  that's partt of the price of running in your choice of servlet
>  container; short of Tapestry being an application server, and not an
>  application framework, it doesn't have sufficient control of things to
>  make it any more seamless.
>
>
>
>  On Tue, Mar 25, 2008 at 2:49 PM, Adam Zimowski <zi...@gmail.com> wrote:
>  > If Page or Component defines Enum internally, Tapestry throws a
>  >  ClassCastException the moment said page or component  class (or even
>  >  the template) is "hot" reloaded due to any kind of change.
>  >
>  >  Can this be fixed/change to allow inner Enums?
>  >
>  >  -adam
>  >  as of 5.0.11
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  >  For additional commands, e-mail: users-help@tapestry.apache.org
>  >
>  >
>
>
>
>  --
>  Howard M. Lewis Ship
>
>  Creator Apache Tapestry and Apache HiveMind
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Inner Enums of Pages and Components

Posted by Howard Lewis Ship <hl...@gmail.com>.
I'm kind of surprised about that;  are you storing the enum values
outside of the page instance (i.e. in the session?)

Inner classes are loaded by the disposable component class loader (the
class loader that handles retry logic and class transformation).  When
a class changes, the class loader, plus and objects instantiated from
that class loader, are discarded.

If you place such an object in the session, it will hang around
(keeping the class loader from being garbage collected) ... AND when
the stored value is assigned to a field of the newly loaded page
instance, it will fail with a ClassCastException because there's a new
class (with the same name) loaded by a new class loader.

I'd love to patch up these "leaky abstractions" a bit better, but
that's partt of the price of running in your choice of servlet
container; short of Tapestry being an application server, and not an
application framework, it doesn't have sufficient control of things to
make it any more seamless.

On Tue, Mar 25, 2008 at 2:49 PM, Adam Zimowski <zi...@gmail.com> wrote:
> If Page or Component defines Enum internally, Tapestry throws a
>  ClassCastException the moment said page or component  class (or even
>  the template) is "hot" reloaded due to any kind of change.
>
>  Can this be fixed/change to allow inner Enums?
>
>  -adam
>  as of 5.0.11
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Inner Enums of Pages and Components

Posted by Adam Zimowski <zi...@gmail.com>.
Yeah, I haven't thought of that. I'll give it a shot, it just may work for us :)

On Tue, Mar 25, 2008 at 5:03 PM, Davor Hrg <hr...@gmail.com> wrote:
> This is most likely due to serialization of the enum in the session,
>
>  I use a workarround that does not affect the code too much,
>  and I can track references to the enum.
>
>  I persist a string variable, but always use enum.name()
>  to change the variable.
>
>  I use this to keep track of major blocks that are visible in a page or comp
>
>   private enum Blocks{EDIT,DETAILS, EDIT_DANGER}
>
>  I persist the string
>     @Persist            private String      _currentBlock = Blocks.EDIT.name
>  ();
>  I return block:
>     public Block getCurrentBlock(){
>         return _resources.getBlock(_currentBlock);
>     }
>
>  whne I change current block, I use the enum
>
>     public void resetView() {
>         _currentBlock = Blocks.DETAILS.name();
>         _splitGoodId = null;
>         _containerId = null;
>     }
>
>     public boolean onGoTo() {
>         resetView();
>         return true;
>     }
>
>     public boolean onGoToEditor() {
>         _currentBlock = Blocks.EDIT.name();
>         return true;
>     }
>
>  this might be helpfull... and it is not too far from classic usage
>
>  Davor Hrg
>
>  On Tue, Mar 25, 2008 at 10:49 PM, Adam Zimowski <zi...@gmail.com>
>  wrote:
>
>
>
>  > If Page or Component defines Enum internally, Tapestry throws a
>  > ClassCastException the moment said page or component  class (or even
>  > the template) is "hot" reloaded due to any kind of change.
>  >
>  > Can this be fixed/change to allow inner Enums?
>  >
>  > -adam
>  > as of 5.0.11
>  >
>
>
> > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  > For additional commands, e-mail: users-help@tapestry.apache.org
>  >
>  >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Inner Enums of Pages and Components

Posted by Davor Hrg <hr...@gmail.com>.
This is most likely due to serialization of the enum in the session,

I use a workarround that does not affect the code too much,
and I can track references to the enum.

I persist a string variable, but always use enum.name()
to change the variable.

I use this to keep track of major blocks that are visible in a page or comp

 private enum Blocks{EDIT,DETAILS, EDIT_DANGER}

I persist the string
    @Persist            private String      _currentBlock = Blocks.EDIT.name
();
I return block:
    public Block getCurrentBlock(){
        return _resources.getBlock(_currentBlock);
    }

whne I change current block, I use the enum

    public void resetView() {
        _currentBlock = Blocks.DETAILS.name();
        _splitGoodId = null;
        _containerId = null;
    }

    public boolean onGoTo() {
        resetView();
        return true;
    }

    public boolean onGoToEditor() {
        _currentBlock = Blocks.EDIT.name();
        return true;
    }

this might be helpfull... and it is not too far from classic usage

Davor Hrg

On Tue, Mar 25, 2008 at 10:49 PM, Adam Zimowski <zi...@gmail.com>
wrote:

> If Page or Component defines Enum internally, Tapestry throws a
> ClassCastException the moment said page or component  class (or even
> the template) is "hot" reloaded due to any kind of change.
>
> Can this be fixed/change to allow inner Enums?
>
> -adam
> as of 5.0.11
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>