Serialization vs xmlencoder bean

Hi,
I would like to be able to save/load a DefaultTreeModel object from file.
However the Java 5 api contains this warning for all Swing components.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.
So is XMLEncoder the only longterm option for saving Swing objects?
Also do the objects I encode have to be Java beans?
So is it recommended I use XMLEncoder for Swing objects and Java serialization other objects?
Regards,
Nikolas.

A look into the API docs for XMLEncoder will give you a sample example of how to use it.
http://java.sun.com/j2se/1.4.2/docs/api/java/beans/XMLEncoder.html

Similar Messages

  • Serialize stateful session bean to xml

    Hi,
    Here is the scenario:
    1. Stateful session bean is created.
    2. XML message is sent to the queue. The xml message needs to have a reference to the session bean created in the first step.
    3. MDB.onMessage reads the xml and invokes a method on the stateful bean
    What are the different approaches to implement the second step? That is to create a reference to an instance of the session bean and at runtime invoke the same instance.
    Thank you

    Hi,
    I don't know if it works with a serialization to xml, but for (for example) a web application you would probably put the handle to the statefull session bean in the session. If I am not wrong, the implementation of handle object should be serializable (http://java.sun.com/products/ejb/javadoc-1.0/javax.ejb-javadoc/javax.ejb.Handle.html)
    Please post a reply if it worked, because the problem is interesting
    Georges
    Handle h = (Handle) session.getAttribute("myStateful");
    MyStateful statefulBean = null;
    if ( h == null) {
    statefulBean = createStatefulEJB();
    if (statefulBean != null) {
    h = statefulBean.getHandle();
    session.setAttribute("myStateful", h);
    } else {
    statefulBean = (MyStateful) PortableRemoteObject.narrow (h.getEJBObject() , MyStateful.class);

  • Java 5 Enums serialization with XMLEncoder...

    Hello,
    I'd like to know why a bean attribute whose type is a Java 5 enum is
    not saved when using XMLEncoder. This field is in fact ignored...
    Anybody knows how to persist such fields using standard JDK (I mean
    no third party library) ?
    public enum TestBeanEnum {
        R160x100,
        R320x200,
        R640x480,
        R800x600,
        R1024x768,
        R1280x1024,
        R1600x1200;
    public class Setup {
        private TestBeanEnum a0;
        private boolean a1;
        public Setup() {
        public boolean isA1() {
            return a1;
        public void setA1(boolean a1) {
            this.a1 = a1;
        public TestBeanEnum getA0() {
            return a0;
        public void setA0(TestBeanEnum a0) {
            this.a0 = a0;
        private static void save(Setup setup, File file) throws IOException {
            FileOutputStream out = new FileOutputStream(file);
            XMLEncoder encoder = new XMLEncoder(out);
            encoder.writeObject(setup);
            encoder.close();
            out.close();           
    ...Only the attribute a0 is not saved all over, even relatively complex data
    types are automatically persisted.
    I also find a strange behavior, the keyword "transient" seems to be ignored
    by the XMLEncoder and a transient field is made persistent !!!
    Did I miss something ? Is this strange behavior a bug ?
    Thanks for all,
    David Crosson.

    looks like a bug to me
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403

  • Serialization using XMLEncoder/XMLDecoder - problems for SpringLayout

    I am using JDK 1.4.0 (obviously, as I have problems with XMLEncoder... :o)
    What I need to do is create a JFrame with some Swing components inside (JPanel's, JLabel's, etc.), to save it as an XML file and be able to restore it later.
    Everything went OK at the beginning, but there came the time to manage the layout part. For various reasons, the most appropriate layout manager for my application is SpringLayout.
    The first step was again OK: when defining a SpringLayout for a panel, this property was transferred to the XML by XMLEncoder and restored by XMLDecoder.
    But then, the happy days are over! In order for a SpringLayout to work, one must obviously define lots of SpringLayout.Constraints, using Spring's. But none of these things are transferred by XMLEncoder to the XML.
    And, quite naturally, even if I modify manually the XML to include some constraint info, the XMLDecoder won't read that info!
    Does anybody know if there is any trick about this? Or is there a known bug concerning the serialization of Spring's, and you know about a workaround?
    Thanks a lot,
    Adrian

    Hi Adrian, there are no persistence delegates defined for SpringLayout and its children.
    I spent quite some time over the last six months trying to get SpringLayouts to save
    correctly - but failed. There are two bugs in the way - both of which should be fixed for
    1.4.1 (I think). One was in SpringLayout - the other in XMLEncoder itself:
    http://developer.java.sun.com/developer/bugParade/bugs/4679556.html
    One thing you said in your note that I thought Id comment on. You can edit the XML file manually
    and this will (probably) lead to a solution. The XMLDecoder is an interpreter - it doesn't need access
    to persistence delegates or require any knowledge of the swing APIs to work.
    Hope that helps.
    Philip

  • How to Serialize/Deserialize Beans with Web Services using DII client

    Dear All;
    I had developed a web serivce by Oracle JDeveloper [J2EE 1.4 (JAX-RPC)] and trying to invoke methods within through DII client using Apache Axis 1.
    The Beans I am using are structured as follows:
    public class InBean {
    public InBean() {
    private int x;
    private float y;
    public setters/getters for x
    public setters/getters for y
    public class OutBean {
    public OutBean() {
    private String inString;
    private String outString;
    public setters/getters for inString
    public setters/getters for outString
    The (InBean) is used as method input and the (OutBean) is used as method output.
    The problems I am facing are as follows:
    [1] How to serialize/desrialize the Beans as they are not registered with Apache Axis 1?
    [2] How to invoke the Beans using Dynamic client DII and not classic proxy and Stubs?
    [3] How to create the Beans using WSD2Java of the Apache Axis 1 ?
    In case you have any helping URL's, Book names or sample code, please attach as they will be very helpful.
    Thanks alot for the help.-----
    Best Regards,
    Ahmed M. Abbas

    You will find some working code at :
    http://ksoap.objectweb.org/software/downloads/index.html
    It's code that use kSOAP and kXML implementations ....
    If you will also find some useful information here :
    http://developers.sun.com/techtopics/mobility/apis/articles/wsa/
    http://www-106.ibm.com/developerworks/wireless/library/wi-jsr/
    http://www-106.ibm.com/developerworks/wireless/library/wi-xmlparse/
    Regards.

  • Stateful Session Beans are not passivated / serialized when cache idle time

    Technology: Sun Application Server version 7.0.0_01; JDK 1.4.1; developed on Windows 2000; Tested on Sun Solaris.
    Initial error on Sun Solaris:
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr: Exception in thread "service-j2ee-25" org.omg.CORBA.OBJ_ADAPTER: vmcid: SUN minor code: 1015 completed: No
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.POA.GenericPOAServerSC.preinvoke(GenericPOAServerSC.java:389)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.POA.ServantCachePOAClientSC.initServant(ServantCachePOAClientSC.java:112)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.POA.ServantCachePOAClientSC.setOrb(ServantCachePOAClientSC.java:95)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.iiop.CDRInputStream_1_0.createDelegate(CDRInputStream_1_0.java:760)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.iiop.CDRInputStream_1_0.internalIORToObject(CDRInputStream_1_0.java:750)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.iiop.CDRInputStream_1_0.read_Object(CDRInputStream_1_0.java:669)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.iiop.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:890)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.iiop.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:884)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.iiop.CDRInputStream.read_abstract_interface(CDRInputStream.java:307)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.se.internal.io.IIOPInputStream.readObjectDelegate(IIOPInputStream.java:228)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.se.internal.io.IIOPInputStream.readObjectOverride(IIOPInputStream.java:381)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:318)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.enterprise.iiop.IIOPHandleDelegate.getStub(IIOPHandleDelegate.java:58)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.enterprise.iiop.IIOPHandleDelegate.readEJBObject(IIOPHandleDelegate.java:38)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.ejb.portable.HandleImpl.readObject(HandleImpl.java:91)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.se.internal.io.IIOPInputStream.readObject(Native Method)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.se.internal.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1298)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.se.internal.io.IIOPInputStream.inputObject(IIOPInputStream.java:908)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:261)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:981)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:287)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.sun.corba.ee.internal.javax.rmi.CORBA.Util.copyObject(Util.java:598)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at javax.rmi.CORBA.Util.copyObject(Util.java:314)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.telstra.nodeman.ejb._NodeMaint_Stub.getHandle(Unknown Source)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.telstra.nodeman.arch.NMAViewBeanProxy.checkBeans(NMAViewBeanProxy.java:631)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.telstra.nodeman.view.html.NMAStandardButton.handleRequest(NMAStandardButton.java:143)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.telstra.nodeman.arch.NMAViewBeanBase.handleRequest(NMAViewBeanBase.java:1573)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.iplanet.jato.view.ViewBeanBase.dispatchInvocation(ViewBeanBase.java:824)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.iplanet.jato.view.ViewBeanBase.invokeRequestHandlerInternal(ViewBeanBase.java:637)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.iplanet.jato.view.ViewBeanBase.invokeRequestHandler(ViewBeanBase.java:595)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.iplanet.jato.ApplicationServletBase.dispatchRequest(ApplicationServletBase.java:772)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.iplanet.jato.ApplicationServletBase.processRequest(ApplicationServletBase.java:446)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.iplanet.jato.ApplicationServletBase.doPost(ApplicationServletBase.java:324)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.telstra.nodeman.view.ViewServlet.doPost(ViewServlet.java:243)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:720)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrapperValve.java:118)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperValve.java:278)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at java.security.AccessController.doPrivileged(Native Method)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:158)
    [10/Aug/2004:08:04:57] WARNING (17227): CORE3283: stderr:      at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
    The above error caused the server to use all available memory and required a reboot to proceed.
    Subsequent testing against the Sun Appliucation Server 7 on Windows 2000 dev environment using the Sun Studio IDE for debugging and trace statements inserted in the code indicate that the Application Server is removing the Stateful Session Beans when they time out without an ejbPassivate event and without serializing the beans to the data-store. cache-idle-timeout-in-seconds set to 180 and removal-timeout-in-seconds set to 1800.
    The server.log indicates that the beans are timing out:
    [19/Aug/2004:18:15:10] WARNING ( 1664): [NRU-com.telstra.nodeman.ejb.AddressMaintBean]: IdleBeanCleanerTask finished after removing 2 idle beans
    Trace statements inserted in ejbPassivate do not appear in the log.
    It is my understanding that the above timeout should have caused an ejbPasssivate and serialization of the beans.
    The beans have been validated using Sun Java Studio Enterprise 6 with 'EJB validate'.
    My reading of the problem is that the beans are not being serialized and the error occurs when the application attempts to reference (getHandle) the bean after timeout.
    Any suggestions would be appreciated.

    Thanks Thorick.
    I am using NRU caching. WL 7.0 SP2.
    I have not defined idle-timeout-seconds in my weblogic-ejb-jar.xml. As I understand
    the default value for this is 600secs. So the ejbs should be removed after this
    time. Below is the
    weblogic-ejb-jar.xml that I am using.
    <!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN'
    'http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd'>
    <!-- Generated XML! -->
    <weblogic-ejb-jar>
    <weblogic-enterprise-bean>
    <ejb-name>Cart</ejb-name>
    <stateful-session-descriptor>
    <stateful-session-clustering>
    <home-is-clusterable>true</home-is-clusterable>
    <replication-type>InMemory</replication-type>
    </stateful-session-clustering>
    </stateful-session-descriptor>
    <transaction-descriptor>
         <trans-timeout-seconds>
              60
         </trans-timeout-seconds>
    </transaction-descriptor>
    <jndi-name>CartHome</jndi-name>
    </weblogic-enterprise-bean>
    </weblogic-ejb-jar>
    "thorick" <[email protected]> wrote:
    >
    The idle-timeout-seconds property controls the timeout/removal behavior.
    which stateful session cache type are you using ? LRUCache or NRUCache

  • Error while using Jsp Beans

    Hi, i just have written my first bean but i'm getting this erro message:
    java.lang.ClassNotFoundException: Unable to load class userinfo.FormBean
    Can somebody pls help me out.
    Thanks in advance
    JBP
    Below are my codes for the bean and my jsp codes
    Bean:
    package userinfo;
    import java.io.*;
    public class FormBean implements Serializable
    private String name;
    private String email;
    public FormBean()
    name = "test";
    email = "test";
    public void setName(String name)
    this.name = name;
    public String getName()
    return name;
    public void setEmail(String email)
    this.email = email;
    public String getEmail()
    return email;
    Jsp Codes:
    <html>
    <head>
    <title>Login</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <jsp:useBean id="formbean" class="userinfo.FormBean"/>
    <jsp:setProperty name="formbean" property="*" />
    <body bgcolor="#FFFFFF" text="#000000">
    <% if (request.getParameter("name")==null
    && request.getParameter("email"==null)
    { %>
    <form name="form1" method="post" action="process.jsp">
    Name:
    <input type="text" name="textfield">
    <br>
    <br>
    Email:
    <input type="text" name="textfield2">
    <br>
    <br>
    <input type="submit" name="Submit" value="Process">
    </form>
    <% } else {%>
    <p>
    <b>you have provided the following info</b>
    <p>
    <b>Name</b>:<jsp:getProperty name="formbean" property="name"/>
    <p>
    <b>Email</b>:<jsp:getProperty name="formbean" property="email"/>
    <p>
    <%}%>
    </body>
    </html>

    Hi!
    I tried ur bean in my program on javawebserver.
    It didn't work.
    gave error:
    java.lang.ClassNotFoundException: Unable to load class userinfo.FormBean
    then I just added
    import java.io.Serializable;
    in ur bean and tried.
    It gave me error:
    D:\JavaWebServer2.0\tmpdir\default\pagecompile\jsp\_examples\_jsp\_samples\_Brand__new\_mail1.java:19: '}' expected.
    static char[][] jspxhtml_data = null;
    I think the problem with bean is solved.
    U check for the same.
    check the settings of server and classpath .
    write whether it works,
    bye,
    Samir

  • JSPDyn page using a bean

    Trying to create a pretty simple JSPDyn page with a single bean.  I am using NWDS to generate the code.  I am trying to set some initial data in bean to be used on the page later, but it always comes back as NULL.  It's like the creation the generation of the page creates a new instance of bean and loses the reference I create in the controller.
    Here is the code for the dynpage controller:
    package com.my.test;
    import com.my.test.bean;
    import com.sapportals.htmlb.*;
    import com.sapportals.htmlb.enum.*;
    import com.sapportals.htmlb.event.*;
    import com.sapportals.htmlb.page.*;
    import com.sapportals.portal.htmlb.page.*;
    import com.sapportals.portal.prt.component.*;
    public class myTest extends PageProcessorComponent {
      public DynPage getPage(){
        return new myTestDynPage();
      public static class myTestDynPage extends JSPDynPage{
        private bean myBean = null;
        public void doInitialization(){
          IPortalComponentProfile profile = ((IPortalComponentRequest)getRequest()).getComponentContext().getProfile();
          Object o = profile.getValue("myBean");
          if(o==null || !(o instanceof bean)){
            myBean = new bean();
            profile.putValue("myBean",myBean);
          } else {
              myBean = (bean) o;
          // fill your bean with data here...
          myBean.setOutput("test message");
        public void doProcessAfterInput() throws PageException {
        public void doProcessBeforeOutput() throws PageException {
          this.setJspName("myTest.jsp");
    Notice I am setting the data up after the comment "//fill your bean data here".  SAP code generator inserted this comment.
    and here is the bean code
    package com.my.test;
    import java.io.Serializable;
    public class bean implements Serializable {
         private String output;
         public String getOutput( ){
              return output;
         public void setOutput( String value ){
              output = value;
    and finally the jsp page
    <jsp:useBean id="myBean" scope="application" class="com.my.test.bean" />
    <hbj:content id="myContext" >
      <hbj:page title="PageTitle">
       <hbj:form id="myFormId" >
         The value of Output is <%= myBean.getOutput( ) %>
       </hbj:form>
      </hbj:page>
    </hbj:content>
    the output is:
    The value of Output is null
    Anyone have any idea what I am doing wrong here.
    Thanks in advance.
    Clark

    Hi Clark,
    Open the portalapp.xml and delete these two lines
            <property name="ComponentType" value="jspnative"/>
            <property name="JSP" value="pagelet/myTest.jsp"/>
    Rebuild and deploy and it should work.
    Thanks
    Prashant

  • How to layout beans for single page design

    Hey guys. I'm designing a site that uses the Icefaces framework. I've been reading a book called Real World Java EE patterns. I'm kind of confused how to layout the pages. Normally I would have just a POJO class implement serializable for a bean. This bean would then back each page. With a single page design I'm going to have a bunch of elements on the page. Datatables, trees, inputs, calendars etc. Is it normal or best practice to have separate beans for each datatable, calendar, etc or put that all in one bean? I'm not sure how to approach this. Right now each element is a bean and I'm using the @Inject annotation to have the data table talk to the tree and vise versa. This creates really bad code and if I put this as a member of the class I will get a circular reference because the data table bean has to inject the calendar and the calendar has to inject the data table.
    Thanks for any help.

    'best' practice is to not follow blindly what other people say, but to reason yourself what works best for you. It has been stated many times before and I will state it again: best practice does not exist. Only personal opinions about what is best exist. Personal opinions are not facts.
    So choose what works for you. Is the code easy to maintain? Is it readable? Can you perhaps re-use parts of it? Then I'd say you have a winner.
    I'll give you my personal favorite. When working with a page that has input elements, I tend to have two or three beans. Replace XXX with a logical and context sensitive name.
    XXXForm - this is a simple request scoped bean that has the action and event methods and will hold some data for reading purposes for the view, possibly taken from a database.
    XXXStorage - this is a session scoped bean that holds information from the form; if it is an editing function I initialize it with the current state first. Storing this stuff in a session bean makes it very easy to do Ajax stuff and create input cycles that span multiple requests. Also when data is split in multiple pages, the storage class is the one to remember which page is being displayed.
    Optionally, I also have an XXXSearch object, which is a session scoped bean that stores search/sort/filter parameters. I make this session scoped so the information is remembered for the duration of the user's visit, meaning he can navigate away from the page in question, come back and all his choices will still be in place.
    So no, I don't have beans specifically for each component, although I might make simple POJOs to hold information gathered from several sources (for example, information gathered from several database tables). These beans are generally used to fill the rows of a datatable and are just created from within the form class, for example in a @PostConstruct annotated method.

  • Serializing of backing beans

    I have the following backing bean:
    public class BackingBean {
       private UIData dataComp;
       public void setDataComp(UIData d) { dataComp = d; }
       public UIData getDataComp() { return dataComp; }
    }I use it in the JSP as such:
    <h:dataTable binding="#{BackingBean.dataComp}"...>
    </h:dataTable>The above code works fine when the state saving method is set to server. However, when I set the saving method to client, JSF tries to serialize my backing bean. Needless to say, I get serializable exceptions and my app doesn't work with client side state saving.
    For a variety of reasons I don't want my BackingBean to be Serializable. Any ideas on how to make my app work without my BackingBean having to implement Serializable?
    Thanks.

    ~ JSF should not be attempting to serialize your backing bean
    I was under the same impression myself. But my debugging so far suggests otherwise... Below is the stack trace (As you can see, the ViewHandlerImpl.renderView() method is trying to serialize the backing bean):
    javax.servlet.ServletException: Error while saving state in 'session': 'myPackage.MyBackingBean'.
         at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)
         at org.apache.jsp.map$jsp._jspService(map$jsp.java:984)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)
         at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:431)
         at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:355)
         at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:142)
         at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
         at java.lang.Thread.run(Thread.java:536)

  • Serialization/Deserialization Error

    Hi..my aim is to serialize/deserialize my "SoapPair" class , that contains Axis MessageContext obj (SoapPair receives this from its constructor), not serializable object(when trying to normally serialize , it returns "axis MessageContext not serializable")..
    How do I serialize/deser the SoapPair class?
    Do I have to use SerializationContext/Deser context? How?
    Thanks in Advance.

    This forum for Networking and has nothing to do with axis Serialization.
    I am not sure if I remember axis has a deployment descriptor for the web service and there you can define you Serialize/Dez your bean if you do not want to use the default one or you can specify for certain class a serialize/Dez factory serializer.
    Regards,
    Alan Mehio
    London,UK

  • Serialization/Deserialization Error - Axis

    Hi..my aim is to serialize/deserialize my "SoapPair" class , that contains Axis MessageContext obj (SoapPair receives this from its constructor), not serializable object(when trying to normally serialize , it returns "axis MessageContext not serializable")..
    How do I serialize/deser the SoapPair class?
    Do I have to use SerializationContext/Deser context? How?
    Thanks in Advance.

    This forum for Networking and has nothing to do with axis Serialization.
    I am not sure if I remember axis has a deployment descriptor for the web service and there you can define you Serialize/Dez your bean if you do not want to use the default one or you can specify for certain class a serialize/Dez factory serializer.
    Regards,
    Alan Mehio
    London,UK

  • Saving a custom JPanel

    i have a custom jpanel that stores works similary to a drawing tool all classes used inside it are serializable as a result does that mena to save it i can simple serialize the class then when come to load just deserialize is and it should work?

    As JavaDoc says:
    * Portable and version resilient
    * Structurally compact
    * Fault tolerant
    And it's the recomeded way of serailization for **swing**.
    In other words, a xml serialization is "compatible" (to a certain extent) beetween versions of the classes, is more compact because if the property don't change from the original (from a instance without modifications of the bean) it's not serialized. Try to serialize with XMLEncoder and open the document generated. The way the component's graph is reconstructed is very interesting and you can understand why xml serialization is best.
    A personal serialization is needed when the objects you need are too complex

  • Persist Object References..

    Dear all,
    I�ve just finished implementing my own object to XML encoder / decoder. I was wondering if anyone could point me in the right direction with regards to persisting object references, similar to object serialization or java.bean.XMLEncoder / Decoder.
    Many thanks in advance�

    I don't understand your question. Could you clarify ? If you can convert an object to and from XML, what's the problem you're encountering with persisting that information into a file ?
    Dave.

  • How do I view a PDF?

    I have an applet that serializes a transport bean to a servlet on tomcat, the servlet makes a PDF that I want to display on the browser. I had thought that if I simply set the MIME type and return the binary data, the browser would know what to do. But I forgot that in this case the applet is the one in control, not the browser. The browser screen just sits there.
    Here is the code that I use to send the serialized object :
        public InputStream sendPostMessage (Properties args) throws IOException
            String argString = "";  // default
            if (args != null)
                argString = toEncodedString (args);  // notice no "?"
            URLConnection con = servlet.openConnection ();
            // Prepare for both input and output
            con.setDoInput (true);
            con.setDoOutput (true);
            // Turn off caching
            con.setUseCaches (false);
            // Work around a Netscape bug
            con.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
            // Send headers
            sendHeaders (con);
            // Write the arguments as post data
            DataOutputStream out = new DataOutputStream (con.getOutputStream ());
            out.writeBytes (argString);
            out.flush ();
            out.close ();
            return con.getInputStream ();
        }

    Here is the question...
    Given the fact that I am serializing an object to the servlet, and that the applet is sitting there.. Is there a way to make the Browser display the PDF?
    I have my doubts about ShowDocument(URL) as I am generating the PDF on the fly without using a temporary file. (Jasper reports) In addition, aren't there sandbox issues on the server side for creating a file?
    Any other ideas?

Maybe you are looking for