Page 1 of 1

How to update an object with one attribute type String Array

Posted: Fri Aug 07, 2009 12:37 pm
by ConvertFromOldNGs
by Thai Nguyen >> Tue, 24 Aug 2004 4:17:21 GMT

Dear all,

I have one class called Customer. It has an atribute called Type which only receives value from: A, B, C, D. I define this atribute as a String Array. But I don't know how to update this one on Form - using a combo box. Can you help me out of this ? Step by step if possible.

Thanks a lot,

Thai

Re: How to update an object with one attribute type String Array

Posted: Fri Aug 07, 2009 12:37 pm
by ConvertFromOldNGs
by BeeJay >> Wed, 25 Aug 2004 8:11:14 GMT

Firstly, I would suggest that you review the tutorials and the Erewhon sample schema on the JADE Web Site as this will help familiarise you with JADE.

Secondly, can you simultaneously have more than one of these Type values selected for any given customer?

If yes, then you will need to use a multi-select ListBox rather than a ComboBox to allow the user to select multiple values. You can then iterate the ListBox entries, checking for the selected value(s) using code along the lines of the following - I assume that a local variable theCust has previously been setup to reference the instance of Customer you wish to update:

// Clear out prior values first
theCust.allTypes.clear();

// Now setup new values based on their selection
foreach count in 1 to lbxCustTypes do
if lbxCustTypes.itemSelected[ count ] then
theCust.allTypes.add( lbxCustTypes.itemText[ count ];
endif;
endforeach;

Note that this code assumes that the property for your StringArray is Customer::allTypes and that it is a public property. In a real world application, it would be preferable to have a transaction agent that you use to perform this update and any data validation logic that may be required. Note that none of this code has been compiled in JADE so it may have some syntax errors.

If you can only ever have one type selected for a given customer, then you could use a ComboBox and you would also use either a String (length=1) or a Character property not a StringArray on the Customer class. Your code would then look something like the following:

theCust.type := cbxCustType.text ;

For a ComboBox, the text property will be the same value as the currently selected entry in the ComboBox.

For the code to populate your ComboBox, or ListBox, you could use some hard-wired code something along the lines of the following:

cbxCustType.addItem("A");
cbxCustType.addItem("B");
cbxCustType.addItem("C");
cbxCustType.addItem("D");

Depending on your application requirements, rather than hard-wiring the values you may want to consider getting these values from a collection of say a CustomerType class to allow end users of your system to customise the CustomerType codes to suit their particular requirements. Assuming you then have some root object with a collection of these CustomerType instances, you could use the listCollection or displayCollection method as follows:

cbxCustType.listCollection( app.myRoot.allCustomerTypes, true, 0 );

Then, you would need to implement the displayEntry method, or displayRow method, something along the lines of the following:

return theObj.CustomerType.code ;

where the CustomerType::code property has the values A, B, C, D respectively, one value per each of the 4 instances of this class.

I trust this is of some assistance, and can I reiterate that you should seriously consider completing the online tutorials and/or downloading the Erewhon sample schema from the JADE Web Site.

Cheers,
BeeJay.

Re: How to update an object with one attribute type String Array

Posted: Fri Aug 07, 2009 12:37 pm
by ConvertFromOldNGs
by thai nguyen >> Wed, 25 Aug 2004 9:00:15 GMT

Thanks very much for your help, BeeJay.

Things are very clear now.

Best,

Thai