Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

event.getValue?

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does the ev.getValue() returns the old value of the attribute if the attribute is replaced?
 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it's because it's useful.

Let's imagine we're using a session.
You could easily get the new value from the session,
but without the old value being stored in the event, you would have no other way of getting it.

MG
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Becase it was designed that way. It allows you to somehow check the previous value if you need it.


[ September 24, 2007: Message edited by: John Stone ]
 
James Mark
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no other way to get the old value back once it is replaced.right?

the new value can be fetched easily...
HttpServletRequest request=(HttpServletRequest )event.getServletRequest();
Object o=request.getAttribute("attributeName");

If you need to know the old value at some later point do it as follows.

Object o1=event.getValue();

set o1 in whatever scope you want for later use in the Application.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Sounds like I just have to take it just like that. But why would I ever need to know the old value is what baffles me. Will there be such a need in real time?
 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Logging?
i.e. if you wanted in your logs it to read "updated value x from a to b".
Where would you put this line?
If you put it in the listener, and the listener can get the old value, it works well.
If you can't get it in the listener, you'll need to stash it somewhere in your business logic code before you update it and the listener is called. That means the developers would have to remember to put in a call before EVERY update, or the issue wouldn't be logged.
You now have 100's of logging calls, when only 1 was needed.
Maintenance headache.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark, to some extent this seems reasonable. Thanks again for the help.
 
Olivier Croisier
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or maybe to have a chance to veto the change ?
This could be used to emulate javabean's VetoableChangeListener : if the new value doesn't meet some requirements, you prevent it from being actually changed.
I guess it could be used to build a validation framework... or not
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic