It works fine for me.
I have a class of objects that writes additional information using
writeObject, reads it back in for additional initialization on
readObject, and even occasionally replaces itself using resolveObject.
Maybe this will help you find the problem.
private void writeObject(java.io.ObjectOutputStream out)
throws IOException
{
Logger logger = Logger.getLogger("serialization");
if (null == this.getDataContext())
{
logger.info("writeObject: " + this.getClass().getName() + "
[" + String.valueOf(this.hashCode()) + "] has no DC.");
logger.info("writeObject: " + this);
Thread.dumpStack();
}
out.writeBoolean(Boolean.TRUE ==
this.getDataContext().getUserProperty("temporary"));
out.defaultWriteObject();
if (Boolean.TRUE == this.getDataContext().getUserProperty("temporary"))
{
logger.info("writeObject: " + this.getClass().getName() + "
[" + String.valueOf(this.hashCode()) + "] has DC [" +
String.valueOf(this.getDataContext().hashCode()) + "] and is marked
temporary.");
}
else
{
logger.info("writeObject: " + this.getClass().getName() + "
[" + String.valueOf(this.hashCode()) + "] has DC [" +
String.valueOf(this.getDataContext().hashCode()) + "] and is not
marked temporary.");
}
}
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException
{
boolean isInTemporaryDataContext = in.readBoolean();
in.defaultReadObject();
this.isInTemporaryDataContext = isInTemporaryDataContext;
Logger logger = Logger.getLogger("serialization");
if (null != this.getDataContext())
{
if (isInTemporaryDataContext)
{
logger.info("readObject: " + this.getClass().getName() +
" [" + String.valueOf(this.hashCode()) + "] has DC [" +
String.valueOf(this.getDataContext().hashCode()) + "] and is marked
temporary.");
}
else
{
logger.info("readObject: " + this.getClass().getName() +
" [" + String.valueOf(this.hashCode()) + "] has DC [" +
String.valueOf(this.getDataContext().hashCode()) + "] and is not
marked temporary.");
}
}
else
{
if (isInTemporaryDataContext)
{
logger.info("readObject: " + this.getClass().getName() +
" [" + String.valueOf(this.hashCode()) + "] has no DC and is marked
temporary.");
}
else
{
logger.info("readObject: " + this.getClass().getName() +
" [" + String.valueOf(this.hashCode()) + "] has no DC and is not
marked temporary.");
}
}
}
/**
* Substitute self with an object registered in thread
* DataContext with the same ID.
*/
protected Object readResolve() throws ObjectStreamException
{
if (null == getDataContext())
{
if (isInTemporaryDataContext)
{
Logger logger = Logger.getLogger("serialization");
logger.info("readResolve: " + this.getClass().getName() +
" [" + String.valueOf(this.hashCode()) + "] has no DC and is marked
temporary.");
return this;
}
else
{
Logger logger = Logger.getLogger("serialization");
logger.info("readResolve: " + this.getClass().getName() +
" [" + String.valueOf(this.hashCode()) + "] has no DC and is not
marked temporary.");
DataContext context;
try {
context = DataContext.getThreadDataContext();
}
catch (IllegalStateException e) {
throw new NotActiveException("Can't deserialize
object for id '"
+ getObjectId()
+ "' - no DataContext bound to thread.");
}
// return context.registeredObject(getObjectId());
return context.localObject(getObjectId(), null);
}
}
else
{
Logger logger = Logger.getLogger("serialization");
logger.info("readResolve: " + this.getClass().getName() + "
[" + String.valueOf(this.hashCode()) + "] has DC [" +
String.valueOf(this.getDataContext().hashCode()) + "].");
return this;
}
}
On 4/2/07, I Faces <[EMAIL PROTECTED]> wrote:
I have an xhtml page with t:saveState references a backing bean. The backing
bean is serializable and I have two methods private void readObject, private
void writeObject however neither of these get called.
As I understand it these methods should get called when an object is
serialized. Is there something wrong with the JSF implementation of
saveState such that these methods do not get called as they should?
How do I verify that saveState is working correctly? After stepping through
the code, doe not look like the <t:saveState does anything at all.
thanks for your help
I
--
View this message in context:
http://www.nabble.com/%3Ct%3AsaveState%3E-not-working---not-serializing-correctly.-tf3507948.html#a9797927
Sent from the MyFaces - Users mailing list archive at Nabble.com.