selectItems from database

Hi to all,is there a sample code on how to fill a selectItems list from a database ?many thanks
[123 byte] By [Zufolo] at [2007-9-30 2:45:06]
# 1

Hello Zufolo,

Here is a sample of how I have managed to do it:

public void someMethod() {

// 1. get the managed bean of the page to call next

FacesContext context = FacesContext.getCurrentInstance();

VariableResolver vr = context.getApplication().getVariableResolver();

NewOrderBean nob = (NewOrderBean) vr.resolveVariable(context, "NewOrderBean");

// 2. call JDBC delegate passing sql request

list = OracleDbServicer.jdbcNativeQueryCall(QueryConstants.fetchApproverList(order.getOrderNumber()));

iter = list.iterator();

// 3. get data from arraylist of hashMaps

while(iter.hasNext()) {

HashMap row = (HashMap) iter.next();

SelectItem item = new SelectItem((String) row.get("AC_PK"),

(String) row.get("AC_NAME"),

(String) row.get("AC_NAME"));

nob.getApprovalChainList().add(item);

}

}

The above method is invoked from an eventHandler instance referenced by the backingBean. It delegates processing a request for database info to a backend class that will return an ArrayList of HashMaps (where each row found represents one element in the arrayList returned). The NewOrderBean is the actual backing bean used by the next page to be called. The "nob" instance contains an ArrayList variable

that is populated here with SelectItems.

Hopefully this will help.

KamauObasi at 2007-6-29 10:28:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
thanks, I'll try
Zufolo at 2007-6-29 10:28:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...