a couple of items from my bag o' tricks:
-- Curt Springer Team ND
/**
* When you execute getValue on a CSpDisplayField, you get a CSpValue.
This could represent
* a simple value, or a CSpVector of simple values, or a CSpVector
containing CSpVectors,
* depending on the number of rows and the hierarchical structure of the page.
* <br><br>
* This recursive utility method returns a Vector of simple CSpValues that
flattens
* out the passed CSpValue, with the values in the order in which they
appeared on the page,
* left to right and top to bottom.
* @param caller Standard for static methods<--OUR CONVENTION FOR STATIC
METHODS, CAN BE OMITTED
* @param fieldvalue Returned from getValue
* @return Vector Contains all the simple CSpValues
* @see getWebVarOccurrences
*/
public static Vector extractSimpleValues(HMSLog caller, CSpValue
fieldvalue) throws Exception
{
try
{
Vector returnvector = new Vector();
if (!(fieldvalue instanceof CSpVector))
{
returnvector.addElement(fieldvalue);
}//if (!(fieldvalue instanceof CSpVector))
else
{
for (Enumeration e=((CSpVector)
fieldvalue).elements();e.hasMoreElements();)
{
CSpValue nextvalue = (CSpValue) e.nextElement();
Vector v = extractSimpleValues(caller, nextvalue);
//add returned values to the list
for (Enumeration f = v.elements();f.hasMoreElements();)
{
CSpValue anothervalue = (CSpValue) f.nextElement();
returnvector.addElement(anothervalue);
}//for (Enumeration f = v.elements();f.hasMoreElements;)
}//for (Enumeration e=fieldvalue.elements();e.hasMoreElements;)
}//else
return(returnvector);
}//try
catch(Exception ex)
{
caller.writeLog(caller, "extractSimpleValues, unexpected exception:" +
ex);
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^
//CAN SUBSTITUTE CSpLog.send, JUST NEED TO COME UP WITH FIRST ARGUMENT,
CAN'T USE
//'this' IN A STATIC METHOD
throw(ex);
}//catch(Exception ex)
}//public static Vector extractSimpleValues(HMSLog caller, CSpValue
fieldvalue)
Also:
=======
/**
* If a field repeats on an ND page, its values are sent back as multiple
* web variables. The first value (#0 in java terms) is sent back as a web
var
* whose name matches the field. Thus for any field, whether it repeats or
not,
* <i>getWebVar("fieldname")</i> will return the first value.
* <br><br>
* If there is a second value, it will be available through ND in a web var
whose
* name is <i>fieldname[1]</i>. Note that this is a string that looks like
a reference
* to an array, but there is no array. For any value beyond the first one,
the actual
* name of the web variable will be <i>fieldname[N]</i>, where N is the
occurrence of the field
* (e.g. N="5", no leading zeros, for the sixth entry).
* <br><br>
* In the case of nested repeateds, the nesting is flattened out. If a
page has a CSpRepeated
* called r1, and r1 contains a CSpRepeated called r2, and r2 contains a
textbox called tb1, tb1's
* web var names will still contain a single number. If there are 2
occurrences of r1, and there is
* one occurrence of r2 within the first occurrence of r1, and two
occurrences of r2
* within the second occurrence of r1, there will be three occurrences of
r2 on the page,
* and thus the web vars for tb1 will be named tb, tb[1] and tb[2], not
tb[0,0],
* tb[1,0], and tb[1,1] as one might think.
* <br><br>
* All of this is normally masked over by using <i>getValue</i> on a field
reference, or
* ,<i>getDisplayFieldValue</i> on a page or repeated reference. The
following
* problems present when you use the vanilla ND approach:
* <ul>
* <i>getValue/getDisplayFieldValue</i> only work for fields that are
defined through
* the ND studio as being children of an ND page. In some cases, we will
create html for
* fields that are not known to the ND page, perhaps by adding a suffix to
the name of
* a known page field (e.g. when we split a date into its month and year
components).
* <li><i>getValue/getDisplayFieldValue</i> returns inconsistently, in that
if there is only
* one occurrence the return is a simple CSpValue, but if there is more
than one occurrence,
* the return is a compound CSpVector of which each entry is either the
simple CSpValue for the
* corresponding occurrence, or, in the case of nested repeateds (as in the
above
* example), another compound CSpVector containing the simple CSpValues for
the
* occurrence of the upper-level repeated. This is a hassle for
template-level
* code that is set up to
* deal with 1 or more occurrences. When
<i>getValue/getDisplayFieldValue</i> is
* used, it frequently is necessary to flatten the return into a single-level
* Vector, if it is a CSpVector that contains one or more CSpVectors, or,
if it
* is a simple value, to build a Vector and drop the value in, in order to
have
* a Vector for the next stage of processing.
* <li><i>getValue/getDisplayFieldValue</i> return compound CSpVectors and
simple
* CSpValues. HMS processing usually needs to deal with generic java, either
* compound Vectors or simple Objects (String, Integer, etc.)
* </ul>
* This method takes a String representing a web variable root name, and
returns
* a Vector containing the results of calling
<i>CSpider.getWebVar("webvarname")</i>
* followed by the results of calling
<i>CSpider.getWebVar("webvarname[1]")</i>,
* <i>CSpider.getWebVar("webvarname[2]")</i>, and so forth, until no further
* occurrences are found. Each web value is converted to a generic java
String.
* <br><br>
* @param webvar Root name of web variable
* @return Vector The web values corresponding to the web variable, as Strings
* @exception A NullPointerException will be thrown if there is no web
variable
* corresponding to the web variable root name.
*
* @see #extractSimpleValues
*/
public static Vector getWebVarOccurrences(HMSLog caller, String webvar)
throws Exception
{
//caller.writeLog(caller, "at beginning of getWebVarOccurrences");
NullPointerException npe=null; //this will be thrown if webvar not
valid
try
{
webvar=webvar.trim();
Vector returnvector = new Vector();
String value = null;
//check first occurrence
try
{
value=CSpider.getWebVar(webvar).stringValue();
}//try
catch (Exception ex1)
{
//do nothing this just in case ND ever decides to throw
exception
//for an invalid web var
}//catch (Exception ex1)
finally
{
//whether or not ND threw an exception, throw NPE if not valid
//web var
if (value == null)
{
npe = new NullPointerException("'"+webvar+"' is not a
valid web
variable name");
throw (npe);
}//if (value == null)
}//finally
//now cycle through and try to find other occurrences
returnvector.addElement(value);
int currentindex = 0;
value = null;
boolean nomore = false;
//caller.writeLog(caller, "about to go into loop");
while (!nomore)
{
try
{
value=null;
currentindex++;
value=CSpider.getWebVar(webvar.concat("[")
.concat(Integer.toString(currentindex)).concat("]")).stringValue();
}//try
catch (Exception ex1)
{
//do nothing this just in case ND ever decides to throw
exception
//for an invalid web var
}//catch (Exception ex1)
finally
{
//whether or not ND threw an exception, set flag to stop if
not valid
if (value == null)
{
nomore = true;
}//if (value == null)
else
{
returnvector.addElement(value);
}//else
}//finally
}//while (!nomore)
return(returnvector);
}//try
catch(Exception ex)
{
if (ex != npe)
{
//suppress general message if the exception is because the
webvar
//does not exist
caller.writeLog(caller, "getWebVarOccurrences, unexpected
Exception: " +
ex);
}//if (ex != npe)
throw (ex);
}//catch(Exception ex)
}//public static Vector getWebVarOccurrences(HMSLog caller, String webvar)
At 09:04 PM 5/10/99 -0800, [EMAIL PROTECTED] wrote:
>
>I generally do something as follows:
>
>CSpValue val = getDisplayFieldValue("*tbAddQty");
>
>if (val instanceof CSpVector)
>{
> //processVector();
>}
>else
>{
> //processValue();
>}
>
>-Chip
>
>[EMAIL PROTECTED] wrote:
>>Within an _onWebEvent, I am attempting to do the following:
>>
>> CSpTextBox tbAddQty = (CSpTextBox) getDisplayField("*tbAddQty");
>> CSpVector svAddQty = (CSpVector) tbAddQty.getValue();
>>
>>If the text box tbAddQty has only one occurrence in the repeating group,
the cast to a CSpVector fails.
>>If it has multiple occurrences, the cast is successful.
>>
>>Is there a way to cast tbAddQty to a CSpVector if it has only one
occurrence or do I need to perform
>>this within a Try/Catch block to handle it accordingly?
>>
>>Thanks,
>>
>>Alan Turner
>>Frito-Lay, Inc.
>>[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]