on 11-24-2004 4:37 PM
We are developing simple component(Iview) , using session and component context beans and one jsp page.
After <u>second</u> deploy(we did not make "clean" or "delete" of previously deployed par) of the par file, we have :
ClassCastException when try to assign bean from component context to local variable:
We have exception in follow code:
XBean myXBean = null;
public void doInitialization() throws PageException {
.....//here error:
myXBean=(XBean)myComponentContext.getValue
("myXBeanName");
....
}
It seems this bean exists in component context , but this is already bean of other type(different Class Loaders?).
I had a similar problem with custom beans saved in session. My solution was to logout and login again so that session context linked to previous implementation of the class is lost and recreated with the new one in new deploy.
The other "smarter" option might be to check if "myXBeanName" is instance of your current class implementation... if not just discard it and instanciate a new one.
Object myTempXBean=myComponentContext.getValue
("myXBeanName");
if(myTempXBean instanceof XBean )
{
//cast it and use it
XBean myXBean = (XBean) myTempXBean;
}
else
{
//drop it and instantiate a new one
//because class has changed
}
Give points if this answers your question
Regards
Vitaliano
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for interest.
This code will not work, because instanceof does not pay attention on difference between class loaders.
if(myTempXBean instanceof XBean )
{
//cast it and use it
XBean myXBean = (XBean) myTempXBean;
}
The simplest approach is catch ClassCastException and remove old bean.
But now I try to remove all beans from context in some "destroy" method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.