This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

listeners problem!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I tried to understand listerners with this code, but i discovered that i did't understand anything about listerers after i saw the output!

can anyone kindly explain to me why this happens :S
=========================
you have this scriptlet

<%
Dog a=new Dog();
Dog b=new Dog();
a.setName("popy");
b.setName("lolo");
session.setAttribute("a",a);
session.setAttribute("a",b);
session.removeAttribute("a");
%>

and following listeners...

public class Dog implements HttpSessionBindingListener
{
private String name;

public void valueBound(HttpSessionBindingEvent event)
{
System.out.println("dog bound "+event.getValue());
}

public void valueUnbound(HttpSessionBindingEvent event)
{
System.out.println("dog unbound "+event.getValue());
}

public String toString()
{
return name;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;

}

}
====================================
public class Session HttpSessionListener
{
public void sessionCreated(HttpSessionEvent se)
{
System.out.println("session created "+se.getSession().getId());
}

public void sessionDestroyed(HttpSessionEvent se)
{
System.out.println("session destroyed "+se.getSession().getId());
}

}
=================================================
public class SessionAtt implements HttpSessionAttributeListener
{
public void attributeAdded(HttpSessionBindingEvent se)
{
System.out.println("attribute added in session: "+se.getValue());
}

public void attributeRemoved(HttpSessionBindingEvent se)
{
System.out.println("attribute removed in session: "+se.getValue());
}

public void attributeReplaced(HttpSessionBindingEvent se)
{
System.out.println("attribute replaced in session: "+se.getValue());
}

}

==========
and this is the output

session created 6AAD1A8E522E94AFCE0254BF06897C3B
dog bound popy
attribute added in session: popy
dog bound lolo
dog unbound null
attribute replaced in session: lolo
dog unbound lolo
attribute removed in session: lolo



 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What result did you expect?
 
Walid El-Sewaify
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder why Binding listener took place before SessionAttribute listeners? what's the order of excution of listeners then??
why first dog unbound returns null while the second returns the dog name?

in attributeReplaced method, is there a way to get reference to the object that has been replaced?
 
No holds barred. And no bars holed. Except this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic