webtier@glassfish.java.net

Re: [webtier] Re: JSF 2.0 composite components bug with facets

From: <webtier_at_javadesktop.org>
Date: Sat, 21 Feb 2009 12:35:30 PST

Ok, the facet problem seems fixed. But my application uses
client side state saving. So I get the following exception:

java.io.NotSerializableException: com.sun.faces.application.view.FacesBeanInfo
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
        at java.util.HashMap.writeObject(HashMap.java:1001)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
        at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
        at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
        at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
        at com.sun.faces.renderkit.ClientSideStateHelper.doWriteState(ClientSideStateHelper.java:251)
        at com.sun.faces.renderkit.ClientSideStateHelper.writeState(ClientSideStateHelper.java:131)
        at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:112)
        at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:149)
        at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:221)
        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:315)
        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:152)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:102)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:311)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)

        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
        at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)



It seems that com.sun.faces.application.view.FacesBeanInfo
has been recently introduced...
Inspired by jsf-ri/src/com/sun/faces/facelets/tag/composite/CompositeComponentBeanInfo.java
(which extends FacesBeanInfo and implements Externalizable),
I changed FacesBeanInfo to:
package com.sun.faces.application.view;

import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.SimpleBeanInfo;


import java.io.Externalizable;
import java.io.ObjectOutput;
import java.io.IOException;
import java.io.ObjectInput;


public class FacesBeanInfo extends SimpleBeanInfo implements BeanInfo, Externalizable {

    private BeanDescriptor descriptor = null;


    @Override
    public BeanDescriptor getBeanDescriptor() {
        return descriptor;
    }

    public void setBeanDescriptor(BeanDescriptor newDescriptor) {
        descriptor = newDescriptor;
    }


    // ----------------------------------------------Methods From Externalizable


    public void writeExternal(ObjectOutput out) throws IOException {

        out.writeObject(getBeanDescriptor().getBeanClass());
        out.writeObject(getBeanDescriptor().getDisplayName());
        out.writeObject(getBeanDescriptor().getName());
        out.writeObject(getBeanDescriptor().getShortDescription());
        out.writeObject(getBeanDescriptor().isExpert());
        out.writeObject(getBeanDescriptor().isHidden());
        out.writeObject(getBeanDescriptor().isPreferred());

        java.util.Enumeration<String> enumeration = getBeanDescriptor().attributeNames();
        while(enumeration.hasMoreElements())
        {
                out.writeObject(Boolean.TRUE);

                String name = enumeration.nextElement();
                out.writeObject(name);
                out.writeObject(getBeanDescriptor().getValue(name));
        }
        out.writeObject(Boolean.FALSE);
    }


    public void readExternal(ObjectInput in)
    throws IOException, ClassNotFoundException {

        setBeanDescriptor(new BeanDescriptor((Class) in.readObject()));
        this.getBeanDescriptor().setDisplayName((String)in.readObject());
        this.getBeanDescriptor().setName((String)in.readObject());
        this.getBeanDescriptor().setShortDescription((String)in.readObject());
        this.getBeanDescriptor().setExpert((Boolean)in.readObject());
        this.getBeanDescriptor().setHidden((Boolean)in.readObject());
        this.getBeanDescriptor().setPreferred((Boolean)in.readObject());

        while((Boolean)in.readObject())
        {
                String name = (String)in.readObject();
                this.getBeanDescriptor().setValue(name, in.readObject());
        }

    }
}

(I found that it is important to save BeanDescriptor attributes (values))
This seems to solve the problem. But I'm not sure this is the right thing to do:
for instance, CompositeComponentBeanInfo saves only getBeanDescriptor().getBeanClass() and does not save BeanDescriptor values...

I guess this problem could be reproduced by svitching ez-comp sample to client side state saving, but I haven't tried that.
[Message sent by forum member 'nzinoviev' (nzinoviev)]

http://forums.java.net/jive/thread.jspa?messageID=333220