[Opensource] typos in EDG
Peter A. Pilgrim
peterp at xenonsoft.demon.co.uk
Wed Dec 10 14:40:52 PST 2003
Maurizio Brilli wrote:
> Larry,
> thanks for your reply. You must have deducted I'm a newbie programmer,
> so thanks for reminding me about being methodic in debugging.
> I must say, the problem arose mostly from the faulty example. From the
> way it was declared, it looked as though when you use both
> setMultiValued and setLookupObject methods, the framework knew it should
> have run a getValidValues on the target object, but that's not the case.
> Thus, something is missing from the example. I think it's useful to show
> here the example in the EDG and the way I had it work, so you can tell
> me if it's correct and eventually update the document.
>
> The EDG (section titled "Multi-Valued Fields" of dbobjects.xml - I still
> haven't checked out your last corrections) says:
>
> <programlisting>
> package org.fooey.testapp.dbobj;
>
> public class Employee extends DBObject {
> // ...
>
> public void setupFields() {
> // ...
>
> setMultiValued("Sex");
> setMultiValued("Dept_Id");
> setLookupObject("Dept_Id", "com.fooey.testapp.dbobj.Department"
> ); <-- (1)
> }
>
>
> public Vector getValidValues(String fieldName)
> throws DBException {
>
> if (fieldName.equals("Sex")) {
> Vector myValues = new Vector();
> myValues.addElement(newValidValue("M", "Male");
> myValues.addElement(newValidValue("F", "Female");
> return myValues;
>
> }
> <-- (2)
> return super.getValidValues(fieldName);
> }
> // ...
> }
>
> </programlisting>
> <para>
> So we have an Employee database object with the attribute "Sex" that
> handles
> the appropriate hard-coded valid values. To complete the look up code we
> implement the valid value look up in the corresponding Department database
> object.
> </para>
> <programlisting>
> package org.fooey.testapp.dbobj;
>
> public class Department extends DBObject {
> // ...
>
> public Vector getValidValues(String fieldName)
> throws DBException {
>
> if (fieldName.equals("Dept_Id")) {
> Vector myValue = this.getValuesDefault(
> "Dept_Id", "Dept_Name" );
> return myValues;
> }
> return super.getValidValues(fieldName);
> }
> // ...
> }
>
The example in the doc that wrote for the EDG talks about Department
data object return a list pair of depertments.
The code `this.getValuesDefault( "Dept_Id", "Dept_Name" )' automatically
retrieve the data from the database as if it is stored like
DEPT_ID DEPT_NAME
======================================
100 PAYROLL
200 SALES
300 MARKETING
400 RESEARCH AND DEVELOPMENT
500 CUSTOMER SERVICES
> </programlisting>
>
> (1) This is not necessary, or better it's what got me confused...
> (2) I added this piece of code:
> if (fieldName.equals("Dept_Id")) {
> Vector myValues = new Vector();
> Department dept = new Department();
> myValues = dept.getValidValues(fieldName);
> return myValues;
>
You confusing the default DBObject.getValidValues() method which retrieves
valid values by using the DBObject that is reference in the meta data of
the data field. The `Department' object is the reference. In other words
it is the target! If you are in Department already, why do you need
to refer to another data object? This is why your code above does not work.
Moreover, getValuesDefault() allows you specify what field name
constitutes the label ("DEPT_NAME") and the field name that is the
value ("DEPT_ID").
> I don't know if this is the right way to implement DbObject-driven
> Multi-Valued Fields, but it surely worked for me.
>
> Thanks a lot again for your time.
> Ciao
> Maurizio
>
There is a choice here
1) Override getValidValues()
2) Do not override getValidValues()
--
Peter Pilgrim
__ _____ _____ _____
/ //__ // ___// ___/ + Serverside Java
/ /___/ // /__ / /__ + Struts
/ // ___// ___// ___/ + Expresso Committer
__/ // /__ / /__ / /__ + Independent Contractor
/___//____//____//____/ + Intrinsic Motivation
On Line Resume
||
\\===> `` http://www.xenonsoft.demon.co.uk/no-it-striker.html ''
More information about the Opensource
mailing list