Confusion on option list filling

I've got myself confused on the filling of comboboxes, listboxes, etc.

The default setup is to populate the lists statically. However I have

never been able to make that work because the obtainConnection never

finds my datasource mapping. I am setting useJNDI and executing

addDataSourceMapping in static initialization on

SQLConnectionmanagerImpl. However when the "populate" method attempts

to obtainConnection, my dataSource is not found (initialization not

done yet? or static SQLConnectionManagerImpl.obtainConnection in

populate method missing it?).

I gave up and decided I wanted to populate the list with every request

anyway. However I don't understand the comments on the ViewBean

concerning making the "option list member variable definitions non-

static". What besides the list itself must be non-static?

When I move the "optionListRef.populate(getRequestContext())" to

a "beginOptionListRefDisplay" method it fails with a null pointer

exception in the populate method on the OptionList class at

m= (SelectQueryModel) rc.getModelManager().getModel(doXXXX.class);

The model class name is correct. I just started debugging this but

decided to write this message for help in clearing up my confusion.

Any ideas? Any experience with staically or dynamically filling option

lists?

[1467 byte] By [Guest] at [2007-11-25 9:27:41]
# 1

There are two separate question here.

Lets take them one at a time.

See embedded comments.

In <a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166136 248038136183193071193172194143142">iPlanet-JATO@egroups.com</a>, <<a href="/group/SunONE-JATO/post?protectID=114232044112042209130232046248130208071 048">dmushrush@e...</a>> wrote:

>

>

> I've got myself confused on the filling of comboboxes, listboxes,

etc.

>

> The default setup is to populate the lists statically. However I

have

> never been able to make that work because the obtainConnection

never

> finds my datasource mapping. I am setting useJNDI and executing

> addDataSourceMapping in static initialization on

> SQLConnectionmanagerImpl. However when the "populate" method

attempts

> to obtainConnection, my dataSource is not found (initialization not

> done yet? or static SQLConnectionManagerImpl.obtainConnection in

> populate method missing it?).

>

First, I suspect that you have a general JNDI configuration problem

here.

This probably has nothing to do with "list" functionality at all.

I recommend first making sure that the JNDI data source lookup is

functioning properly

in a context that does not involve "lists".

Get back to us on this one.

> I gave up and decided I wanted to populate the list with every

request

> anyway. However I don't understand the comments on the ViewBean

> concerning making the "option list member variable definitions non-

> static". What besides the list itself must be non-static?

>

> When I move the "optionListRef.populate(getRequestContext())" to

> a "beginOptionListRefDisplay" method it fails with a null pointer

> exception in the populate method on the OptionList class at

>

> m= (SelectQueryModel) rc.getModelManager().getModel(doXXXX.class);

>

> The model class name is correct. I just started debugging this but

> decided to write this message for help in clearing up my confusion.

> Any ideas? Any experience with staically or dynamically filling

option

> lists?

Ok, here the issue is the appropriate way to dynamically populate

a "list"

as opposed to the static population which is the default.

I must point out that there is a bug in the translated code.

Apologies to all.L.

Lets look at the sample application code for reference.

MigtoolboxSampleApp.MigtoolboxSample.AutoFillPageViewBean.populate

method

The current iMT translation tool generates the following code

/**

*

*

*/

public void populate(RequestContext rc)

{

try {

...

if(rc == null) {

m = new OrdersDataObjectModelImpl();

eContext.setConnection

(SQLConnectionManagerImpl.obtainConnection(m.getDataSourceName()));

}

else {

m = (SelectQueryModel) rc.getModelManager().getModel

(OrdersDataObjectModelImpl.class);

}

...

}

There is a problem with the line

m = (SelectQueryModel) rc.getModelManager().getModel

(OrdersDataObjectModelImpl.class);

It really should be

m = (SelectQueryModel) rc.getModelManager().getModel

(OrdersDataObjectModel.class);

Since the call to getModel expects a Model class, not a model impl

class.

That is the translation tool fault.

It will be corrected in the next patch.

But anyone who has already translated projects should just manually

adjust their OptionList code.

That will be easier than re-translating. It is a trivial change.

Once that change has been made, the remaining steps for dynamic

population is as follows:

1. Change the OptionList member from static to non-static.

FROM

private static DataObjectFillComboBoxOptionList

dataObjectFillComboBoxOptions=new DataObjectFillComboBoxOptionList();

TO

private DataObjectFillComboBoxOptionList

dataObjectFillComboBoxOptions=new DataObjectFillComboBoxOptionList();

2. Disable the static populate() invocation

FROM

static

{

dataObjectFillComboBoxOptions.populate(null);

}

TO

static

{

// dataObjectFillComboBoxOptions.populate(null);

}

3. Add a dynamic call to populate at whatever point seems most

appropriate to you.

Here is an example where I have augmented the ViewBean display event.

/**

*

*

*/

public void beginDisplay()

throws ModelControlException

{

super.beginDisplay();

OrdersDataObjectModelImpl mod =

(OrdersDataObjectModelImpl) getModel(OrdersDataObjectModel.class);

mod.clearUserWhereCriteria();

mod.addUserWhereCriterion

(OrdersDataObjectModel.FIELD_NDNWORDERS_CUSTOMERID,

"LIKE",

"V%");

dataObjectFillComboBoxOptions.populate

(getRequestContext());

}

That is it. Should work like a charm.

Guest at 2007-7-1 16:32:50 > top of Java-index,Development Tools,Java Tools...