confused about custom tags keeping state

Discussion in 'Java' started by luca, Mar 4, 2004.

  1. luca

    luca Guest

    Hello, I am designing a tag library. My problem is that
    my tags (tomcat 4.1.18 on win2k) seem to retain the status
    from one invocation to the next (i.e. variables are
    not initialized each time).

    I tried to look for solutions on google, but I only gather
    that I should do something about calling the release() method
    somewhere (but where?)
    Also, I am confused about multi-threading (what if a doInitTag
    kicks in while a previous instance of the tag is being processed?)

    I have found a workaround by manually reinitializing the tags
    at the beginning of doInitTag(), but this seems unelegant to me...

    ideas? real knowledge?

    thank you

    luca
    luca, Mar 4, 2004
    #1
    1. Advertising

  2. Hi luca

    The documentation for the Interface Tag states "There are two main actions:
    doStartTag and doEndTag. Once all appropriate properties have been
    initialized, the doStartTag and doEndTag methods can be invoked on the tag
    handler. Between these invocations, the tag handler is assumed to hold a
    state that must be preserved. After the doEndTag invocation, the tag handler
    is available for further invocations (and it is expected to have retained
    its properties)."

    The release() method is invoked once all invocations on the tag handler are
    completed. Once a release method is invoked all properties, including parent
    and pageContext, are assumed to have been reset to an unspecified value. The
    page compiler guarantees that release() will be invoked on the Tag handler
    before the handler is released to the GC.

    So that explains the value being retained.

    I normally define my own destructor or initialiser method which I invoke in
    the doEndTag(), re-initializing the members.

    Since each tag would reside in a different pageContext the state will be
    preserved for a thread processing the page.

    Cheers
    Manav
    "luca" <> wrote in message
    news:ySN1c.17789$...
    >
    > Hello, I am designing a tag library. My problem is that
    > my tags (tomcat 4.1.18 on win2k) seem to retain the status
    > from one invocation to the next (i.e. variables are
    > not initialized each time).
    >
    > I tried to look for solutions on google, but I only gather
    > that I should do something about calling the release() method
    > somewhere (but where?)
    > Also, I am confused about multi-threading (what if a doInitTag
    > kicks in while a previous instance of the tag is being processed?)
    >
    > I have found a workaround by manually reinitializing the tags
    > at the beginning of doInitTag(), but this seems unelegant to me...
    >
    > ideas? real knowledge?
    >
    > thank you
    >
    > luca
    >
    >
    Manavendra Gupta, Mar 5, 2004
    #2
    1. Advertising

  3. luca

    luca Guest

    Thanks a lot for your answer. thinking about this again, what about
    explicitly re-initializing the state at the beginning of doStartTag() ?

    Will this guarantee that the old state is reset?

    do you see any problem with that approach?

    thank you

    luca

    Manavendra Gupta wrote:

    > Hi luca
    >
    > The documentation for the Interface Tag states "There are two main actions:
    > doStartTag and doEndTag. Once all appropriate properties have been
    > initialized, the doStartTag and doEndTag methods can be invoked on the tag
    > handler. Between these invocations, the tag handler is assumed to hold a
    > state that must be preserved. After the doEndTag invocation, the tag handler
    > is available for further invocations (and it is expected to have retained
    > its properties)."
    >
    > The release() method is invoked once all invocations on the tag handler are
    > completed. Once a release method is invoked all properties, including parent
    > and pageContext, are assumed to have been reset to an unspecified value. The
    > page compiler guarantees that release() will be invoked on the Tag handler
    > before the handler is released to the GC.
    >
    > So that explains the value being retained.
    >
    > I normally define my own destructor or initialiser method which I invoke in
    > the doEndTag(), re-initializing the members.
    >
    > Since each tag would reside in a different pageContext the state will be
    > preserved for a thread processing the page.
    >
    > Cheers
    > Manav
    > "luca" <> wrote in message
    > news:ySN1c.17789$...
    >
    >>Hello, I am designing a tag library. My problem is that
    >>my tags (tomcat 4.1.18 on win2k) seem to retain the status
    >>from one invocation to the next (i.e. variables are
    >>not initialized each time).
    >>
    >>I tried to look for solutions on google, but I only gather
    >>that I should do something about calling the release() method
    >>somewhere (but where?)
    >>Also, I am confused about multi-threading (what if a doInitTag
    >>kicks in while a previous instance of the tag is being processed?)
    >>
    >>I have found a workaround by manually reinitializing the tags
    >>at the beginning of doInitTag(), but this seems unelegant to me...
    >>
    >>ideas? real knowledge?
    >>
    >>thank you
    >>
    >>luca
    >>
    >>

    >
    >
    >
    luca, Mar 6, 2004
    #3
  4. Yes, that should work too

    Cheers
    Manav
    "luca" <> wrote in message
    news:nKh2c.5786$...
    > Thanks a lot for your answer. thinking about this again, what about
    > explicitly re-initializing the state at the beginning of doStartTag() ?
    >
    > Will this guarantee that the old state is reset?
    >
    > do you see any problem with that approach?
    >
    > thank you
    >
    > luca
    >
    > Manavendra Gupta wrote:
    >
    > > Hi luca
    > >
    > > The documentation for the Interface Tag states "There are two main

    actions:
    > > doStartTag and doEndTag. Once all appropriate properties have been
    > > initialized, the doStartTag and doEndTag methods can be invoked on the

    tag
    > > handler. Between these invocations, the tag handler is assumed to hold a
    > > state that must be preserved. After the doEndTag invocation, the tag

    handler
    > > is available for further invocations (and it is expected to have

    retained
    > > its properties)."
    > >
    > > The release() method is invoked once all invocations on the tag handler

    are
    > > completed. Once a release method is invoked all properties, including

    parent
    > > and pageContext, are assumed to have been reset to an unspecified value.

    The
    > > page compiler guarantees that release() will be invoked on the Tag

    handler
    > > before the handler is released to the GC.
    > >
    > > So that explains the value being retained.
    > >
    > > I normally define my own destructor or initialiser method which I invoke

    in
    > > the doEndTag(), re-initializing the members.
    > >
    > > Since each tag would reside in a different pageContext the state will be
    > > preserved for a thread processing the page.
    > >
    > > Cheers
    > > Manav
    > > "luca" <> wrote in message
    > > news:ySN1c.17789$...
    > >
    > >>Hello, I am designing a tag library. My problem is that
    > >>my tags (tomcat 4.1.18 on win2k) seem to retain the status
    > >>from one invocation to the next (i.e. variables are
    > >>not initialized each time).
    > >>
    > >>I tried to look for solutions on google, but I only gather
    > >>that I should do something about calling the release() method
    > >>somewhere (but where?)
    > >>Also, I am confused about multi-threading (what if a doInitTag
    > >>kicks in while a previous instance of the tag is being processed?)
    > >>
    > >>I have found a workaround by manually reinitializing the tags
    > >>at the beginning of doInitTag(), but this seems unelegant to me...
    > >>
    > >>ideas? real knowledge?
    > >>
    > >>thank you
    > >>
    > >>luca
    > >>
    > >>

    > >
    > >
    > >

    >
    Manavendra Gupta, Mar 7, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ranganath

    Custom Tags within Custom Tags.

    Ranganath, Oct 17, 2003, in forum: Java
    Replies:
    2
    Views:
    440
    Ranganath
    Oct 21, 2003
  2. Mike
    Replies:
    3
    Views:
    858
    Michael Borgwardt
    Jan 9, 2004
  3. A. Brinkmann
    Replies:
    2
    Views:
    1,062
    A. Brinkmann
    Apr 16, 2004
  4. koslows
    Replies:
    0
    Views:
    522
    koslows
    May 12, 2005
  5. Dave
    Replies:
    0
    Views:
    442
Loading...

Share This Page