Retrieving multiple rows from model

Hi,

I want to populate a combo box with values from a sql table. I did the following:

1. Create a View and associated the view with a JDBC model call movieTitleModel. Assume the database field name to be MOVIE_TITLE_NAME

2. Made the view to be Auto Retrieving = movieTitleModel

3. Add a combobox and rename this to movieTitleName.

4. Modify the combobox property sheet with the follwoing

Model Field Binding = MOVIE_TITLE_NAME

Model Reference = movieTitleName

When I executed in, I got a combobox with nothing in it.

I then added the following code to beginDisplay event of the combo box but all I got was just 1 line. The model should return 5 rows. How do I get the model to return all the rows. I even tried executeSelect with all the appropriate values in DatasetModelExecutingContext (DATASET_OFFSET_BEGIN, DATASET_SIZE_ALL_PREFETCH). I got a exception for this.

Is there a way to do this in the model or do I have to resort to doing it in JDBC?

Regards

--

BasicChoiceDisplayField comboBox = (BasicChoiceDisplayField)getDisplayField(CHILD_MOVIE_TITLE_LIST);

MovieTitleModel model = (MovieTitleModel)getModel(test.main.MovieTitleModel.class);

Choice[] opts;

Vector vec = new Vector();

model.beforeFirst();

for (int i = 0; model.next(); i++)

vec.add(new SimpleChoice(model.getValue("MOVIE_TITLE_NAME"), new Integer(i)));

opts = new SimpleChoice[vec.size()];

for (int i = 0; i < opts.length; i++)

opts = (Choice)vec.elementAt(i);

comboBox.setChoices(opts);

return true;

--

[1651 byte] By [cmlee] at [2007-11-25 8:28:05]
# 1

It might be that there is some user where criteria lingering around for this model from a previous request. When you "addUserWhereCriterion", that criterion is saved in the user's HTTP session and reapplied for that model in future requests. This userWhereCriterion is additive, meaning if you keep adding criterion, it is AND'ed to the current user where criteria and save and reapplied to the model.

So it may be necessary for you to clearUserWhereCriterion and apply the appropriate criteria per request (or none at all in this case).

So try doing model.clearUserWhereCriteria() before you execute and let us know if that solves your problem. You can put this code criteria clearing code in beginComponentDisplay, or, since you this is an auto executing model, you can put the code in beforeModelExecutes of your ViewBean. Here is the method since you will not find this via a Studio Event List action like the other events:

public boolean beforeModelExecutes(

Model model,

int executionContext)

{

<get the model and clear the criteria here>

return true;

}

Also, when populating a Choice list, it seems you are doing too much work. Only one loop should be necessary instead of two. Try this instead:

model.beforeFirst();

Choice[] opts = new SimpleChoice[model.getSize()];

for (int i = 0; model.next(); i++)

{

choices =

new SimpleChoice

(

model.getValue("MOVIE_TITLE_NAME"),

new Integer(i)

);

}

comboBox.setChoices(opts);

return true;

Sorry for the poor response time. Please submit more quesitons if this does not solve your problem.

craig

> Hi,

>

> I want to populate a combo box with values from a sql

> table. I did the following:

>

> 1. Create a View and associated the view with a JDBC

> model call movieTitleModel. Assume the database field

> name to be MOVIE_TITLE_NAME

>

> 2. Made the view to be Auto Retrieving =

> movieTitleModel

>

> 3. Add a combobox and rename this to movieTitleName.

>

> 4. Modify the combobox property sheet with the

> follwoing

>Model Field Binding = MOVIE_TITLE_NAME

>Model Reference = movieTitleName

>

> When I executed in, I got a combobox with nothing in

> it.

>

> I then added the following code to beginDisplay event

> of the combo box but all I got was just 1 line. The

> model should return 5 rows. How do I get the model to

> return all the rows. I even tried executeSelect with

> all the appropriate values in

> DatasetModelExecutingContext (DATASET_OFFSET_BEGIN,

> DATASET_SIZE_ALL_PREFETCH). I got a exception for

> this.

>

> Is there a way to do this in the model or do I have

> to resort to doing it in JDBC?

>

> Regards

>

> --

> BasicChoiceDisplayField comboBox =

> comboBox =

> (BasicChoiceDisplayField)getDisplayField(CHILD_MOVIE_

> ITLE_LIST);

> MovieTitleModel model =

> del model =

> (MovieTitleModel)getModel(test.main.MovieTitleModel.cl

> ss);

> Choice[] opts;

>

> Vector vec = new Vector();

>

> model.beforeFirst();

>

> for (int i = 0; model.next(); i++)

> vec.add(new

> vec.add(new

> new SimpleChoice(model.getValue("MOVIE_TITLE_NAME"),

> new Integer(i)));

>

> opts = new SimpleChoice[vec.size()];

> for (int i = 0; i < opts.length; i++)

>opts = (Choice)vec.elementAt(i);

>

> comboBox.setChoices(opts);

>

> return true;

> --

cvconover at 2007-7-1 14:54:41 > top of Java-index,Development Tools,Java Tools...