At 05:08 PM 10/4/99 -0500, Shamdasani Nimmi-ANS004 wrote:
>Aby, Curt, Peter,
>
>Thanks for your responses. I like the idea of creating a custom myPage class
>in case I need to use it for other pages.
>
>I discovered that getChildren() returns everything on the page including any
>buttons and SPIDERSESSION stuff. I am checking for objects of type
>CSpDisplayField and it lists everything on the page.

Yup, as I said.



>Of course I can add code to skip buttons,static text etc. or skip objects
>where getBoundDataField() is Null but is it the normal behavior of
>getChildren()?

Yeah, these are all children of the object on which you are calling the 
method.  You might not want some of this stuff for what you are doing now, 
but others might, for their own purposes.

Here's a utility method that you might find helpful:

         /**
          * Recursive method to cycle through all the children of a page or 
repeated
          * and return a Vector of all the simple (i.e. not repeateds) 
objects at
          * all levels below the starting point.  Skip infrastructure stuff 
like
          * the hidden pagesession object
          * <br><br>
          * @param caller Standard for static methods.
          * @param object Page or Repeated
          * @return Vector all of the children and grandchildren
          */
         public static Vector getSimpleChildren(Object caller, 
CSpDataDrivenVisual object) throws Exception
         {
         try
                 {
                 Vector returnvector = new Vector();
                 loop:  for(Enumeration e = 
object.getChildren().elements(); e.hasMoreElements();)
                         {
                         CSpVisual visual = (CSpVisual) e.nextElement();
                         if (visual instanceof CSpPageSessionHidden)
                                 {
                                 continue loop;  //skip but keep going
                                 }//if (visual instanceof CSpPageSessionHidden)
                         if (visual instanceof CSpDataDrivenVisual)
                                 {
                                 //add children to flattened list
                                 Vector interimvector = 
getSimpleChildren(caller, (CSpDataDrivenVisual) visual);
                                 for (Enumeration iv = 
interimvector.elements(); iv.hasMoreElements(); )
                                         {
                                         returnvector.addElement(iv.nextElem 
returnvector.addElement(iv.nextElement());
                                         }//for (Enumeration iv = 
interimvector.elements(); iv.hasMoreElements(); )

                                 }//if (visual instanceof CSpDataDrivenVisual)
                         else
                                 {
                                 returnvector.addElement(visual);
                                 }//else

                         }//loop:  for(Enumeration e = 
object.getChildren().elements(); e.hasMoreElements();)

                 return returnvector;

                 }//try

         catch (Exception ex)
                 {
                 CSpLog.send(caller, CSpLog.ERROR,  "(static utility 
method) getSimpleChildren, unexpected Exception: " + ex);
                 throw(ex);
                 }//catch (Exception ex)

         }//public static Vector getSimpleChildren(Object caller, 
CSpDataDrivenVisual object) throws Exception




>Here's my small test:
>--------------------------------
>package MCSC;
>
>
>import spider.*;
>import spider.session.*;
>import spider.visual.*;
>import spider.html.*;
>import spider.util.*;
>import java.util.*;
>
>
>
>public class myPage extends spider.visual.CSpPage
>{
>
>         public void saveFieldValues() {
>
>                 CSpVisualsList myPageChildrenList = getChildren();
>
>                 for (Enumeration e = myPageChildrenList.elements();
>e.hasMoreElements();)
>                 {
>                         Object nextValue =  e.nextElement();
>
>                         if (nextValue instanceof CSpDisplayField) {
>
>                                 CSpDisplayField theChild = (CSpDisplayField)
>nextValue;
>
>                                 CSpHtml.sendMessage("Child is
>CSpDisplayField "+ theChild.getName()+"<br>");
>
>                                 CSpDataFieldRef boundDataField =
>theChild.getBoundDataField();
>
>                                 CSpHtml.sendMessage(" with data field="+
>boundDataField+"<br>");
>
>                         }
>
>                         else {
>
>                                 CSpHtml.sendMessage("Child is
>"+getClass()+"<br>");
>
>
>                         }
>
>
>                 }
>
>
>         }
>
>
>} // end of myPage class
>
>
>-----Original Message-----
>From: Curt Springer [mailto:[EMAIL PROTECTED]]
>Sent: Monday, October 04, 1999 12:22 PM
>To: Shamdasani Nimmi-ANS004
>Cc: 'NetDynamics'
>Subject: Re: [ND] Storing the Dataobject into a userSessionObject
>
>
>At 10:34 AM 10/4/99 -0500, Shamdasani Nimmi-ANS004 wrote:
> >Hi All,
> >
> >I have 2 questions:
> >
> >1. How do I get a list of all the display fields in a page and the
> >corresponding dataobject column name that they are bound to.
>
>getChildren() gives you everything one level below the page.  It will
>include the CSpPageSessionHidden object, and any CSpRepeateds.
>
>To get all children at any level, start with the page and call recursively
>on any CSpRepeateds you find along the way.
>
>The children are returned as CSpVisuals.  Data-bound fields are
>CSpDisplayFields.  You can call getBoundDataField() on these to get a
>reference to the bound data object column.
>
>
>
> >2. I have a page based on a dataobject. There is a button on the page which
> >takes the user to next page. On the webEvent of the button,  before
> >proceeding to the next page, I want to store the name and value of all
> >bound display fields(i.e., the whole DataObject) into a userSessionObject.
> >The data in USO will be saved into the database at some later point.
> >
> >Is there a better way than creating a hash table to store the name&value
> >pair of all data fields and then storing the hash table into the session
> >object?
>
>A hash table is a pretty good way to do this.  If you went to the trouble
>to build some sort of class for this, it would probably have a hash table
>inside, anyway.
>
>BTW, you've probably figured out that you should do the field--data column
>lookups as part of init processing, not at runtime.
>
>-- Curt Springer, Team ND
>
>
> >Thanks.
> >
> >-Nimmi
> >
> >_________________________________________________________________________
> >
> >For help in using, subscribing, and unsubscribing to the discussion
> >forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
> >
> >For dire need help, email: [EMAIL PROTECTED]
>
>_________________________________________________________________________
>
>For help in using, subscribing, and unsubscribing to the discussion
>forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
>
>For dire need help, email: [EMAIL PROTECTED]

_________________________________________________________________________

For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html

For dire need help, email: [EMAIL PROTECTED]

Reply via email to