DynamicForm.getItem()/getField() is null

Hi All,

I would like to set value of an form item, because it depends on preceding field.
I call form.getItem(name) method, which results is null.
I can get all the fields with getFields(), there is the named field, but I can’t get it from getField/getItem:(

It is a simple master detail form, created from a listgrid.
The master field generating is here:

    protected FormItem createDefaultComboBox(String formFieldName, String formFieldTitle,
            GwtRpcDataSource dataSource, int pickListWidth,
            String displayField, String[] pickListFields, BaseDTO source) {
        ComboBoxItem item = new ComboBoxItem(formFieldName, formFieldTitle);
        item.setOptionDataSource(dataSource);
        item.setPickListWidth(pickListWidth);
        item.setValueField(FLD_ID);
        item.setDisplayField(displayField);
        ListGridField[] pickFields = new ListGridField[pickListFields.length];
        for (int i=0;i<pickListFields.length;i++)
            pickFields[i]=new ListGridField(pickListFields[i]);
        item.setPickListFields(pickFields);
        item.setRequired(true);
        if (source != null)
            item.setDefaultValue(source.getId().toString());
        return item;
    }

If I get all of the fields, there is 3 item in the result array. The 3rd item is:
TextItem, jsObj is [TextItem ID:isc_TextItem_50 name:teacher]
(It is a Netbeans debugger)
I would like to get it from “teacher” name like form.getItem(“teacher”).

What do I mistake?

ps: my params are
Firefox 3.5,
SmartGwt from svn at yesterday
Gwt 1.6
Debian Linux unstable

thx
Zamek

use the getField method.
are you sure you are passing right name?

getField

All of getItem and getField is retuns null.
Name is ok, because I made a custom getitem, which works well with this name.

   protected FormItem getFormItem(DynamicForm form, String name) {
        if (form == null || StringUtils.isBlank(name))
            return null;
        for (FormItem fi:form.getFields()) {
            if (name.compareTo(fi.getName()) == 0)
                return fi;
        }
        return null;
    }

You should try getField and not getItem on the DynamicForm.

Still, this is the code that dynamic form uses:

        if (fields != null) {
            for (FormItem field : fields) {
                if (name.equals(field.getName())) {
                    return field;
                }
            }
        } else {
....
....

not null but exception!

Here I see, it is not a null result, but an exception!
I wonder it isn’t in hosted browser log, but in Appserver log:

Uncaught JavaScript exception [_1 has no properties] in http://localhost:8080/BelasWeb/com.zamek.belas.Main/sc/modules/ISC_Core.js, line 768

here is my code:

    public void beforeInsert(DynamicForm form) {
        if (this.teacher != null) {
            FormItem fld = this.getFormItem(form, FLD_TEACHER); // my custom, it works well
            fld.setValue(this.teacher.getFullName());

            fld = form.getItem(FLD_TEACHER);  // original from DunamicForm
// it throws an exception
            fld.setValue(this.teacher.getFullName());
        }
    }

in your code, did you try to change this line:

fld = form.getItem(FLD_TEACHER);

with

fld = form.getField(FLD_TEACHER);

?

I always use getFIELD on forms and never had issues.

Exception

  @Override
    public void beforeInsert(DynamicForm form) {
        if (this.teacher != null) {
            FormItem fld = this.getFormItem(form, FLD_TEACHER);
            fld.setValue(this.teacher.getFullName());
            fld = form.getField(FLD_TEACHER);  // Exception here!
            fld.setValue(this.teacher.getFullName());
        }
    }

Uncaught JavaScript exception [_1 has no properties] in http://localhost:8080/BelasWeb/com.zamek.belas.Main/sc/modules/ISC_Core.js, line 768

It is very interesting. How my custom method works, but same as the original?

Colud I debug it on Javascript?
I use Firefox in Linux.
AFAIK gwt obfuscate generated js. Can I set it off?

If you also have eclipse with official google gwt plugin, yes, there is an option to do this, under run configurations.

Dont’ know about netbeans as I don’t use it.

No in Java debugging! Hosted browser is working well in NB.
But it cannot find an obfuscated js. Eclipse can debug all of smartclient obfuscated code? :open_mouth:

I think there is a debug method in Firefox Javascript side.
In smartclient how is debug working?

no, you can’t debug obfuscated but you can generate without obfuscation against your application, not the smartclient .js files

maybe instead of debugging you should try to do a simple test case that does not work (create a dynamic form, add a formItem and use getForm).
If it works then try to add complexity until it stops working…

Oh and maybe use the latest svn version of smartgwt.jar if you don’t use it already…

I downloaded the last version of smartgwt at yesterday evening.

thx for help,