Better way to iterate thru UI SelectItem

I am iterating thru instances of UI SelectItem and then assigning it to java.lang.Object directly. What is the better way to do this

List<DeviceType> models = new ArrayList<DeviceType>();

List<SelectItem> deviceTypes = new ArrayList<SelectItem>();

models = deviceTypeManager.getDeviceTypeList();

//logger.info(" *** DeviceType List Size=*** "+models.size());

for (Iterator it = models.iterator(); it.hasNext();) {

//System.out.println("Inside For Loop Iterator size="+models.size());

Object[] row = (Object[]) it.next();

// System.out.println("ID: " + row[0]);

//System.out.println("Name: " + row[1]);

deviceTypes.add(new SelectItem(row[0]+"",row[1]+""));

}

Regards

Bansi

[787 byte] By [mail2bansia] at [2007-11-26 19:22:28]
# 1

U can do in this way:

private SelectItem[] modelSelectList;

List<DeviceType> models = new ArrayList<DeviceType>();

for (int k = 0; k < models.size(); k++)

{

modelSelectList[k] = new SelectItem();

modelSelectList[k] =(SelectItem)models.get(k);

}

U can set to set method

setmodelSelectList(modelSelectList);

sonara_rahul_2004@yahoo.coma at 2007-7-9 21:43:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

for (Object[] model : models) {

deviceTypes.add(new SelectItem(model[0], model[1].toString());

}

However, rather use a DTO instead of Object[].

public class DeviceType {

private String label;

private Object value;

// + getters + setters

}

for (DeviceType model : models) {

deviceTypes.add(new SelectItem(model.getValue(), model.getLabel());

}

Edit: by the way, I don't understand the relation between DeviceType and Object[]? Why are you casting the DeviceType to Object[]?

Message was edited by:

BalusC

BalusCa at 2007-7-9 21:43:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...