JavaServer Faces - Drop-down menu value not updating consistently in backing bean

Here's one that really has me scratching my head. I have two drop-down menus on my page pulling values from a database. When one changes, an a4j:support event should populate the other with appropriate values. It seems to work fine except that the value in the backing been attached to the first drop-down ("categoryid") is only changingevery other time the menu changes. The action fires every time and the second drop-down always populates. The applicable excerpts from the JSF page and the bean are below, I'd really appreciate some help.

Thanks,

Alex

********************

JSF Page

********************

<h:outputText value="Category" />

<h:selectOneMenu value="#{checkInForm.categoryid}" style="padding:0px;margin:0px;" id="categoryid" >

<a4j:support event="onchange" action="#{checkInForm.loadCategories}" reRender="assetType">

</a4j:support>

<f:selectItems value ="#{checkInForm.categoryList}" />

</h:selectOneMenu>

<h:outputText value="Asset" />

<h:selectOneMenu value="#{checkInForm.assetType}" style="padding:0px;margin:0px;" id="assetType">

<f:selectItems value ="#{checkInForm.assetList}" />

</h:selectOneMenu>

********************

Backing Bean

********************

privateint categoryid;

privateint assetType;

private List categoryList =new ArrayList();

private List assetList =new ArrayList();

....

publicvoid setCategoryList(List categoryList){

this.categoryList = categoryList;

}

public List getCategoryList(){

//open connection

try{

Properties props =new Properties();

props.load(new FileInputStream("c:/projects/properties/oracle.properties"));

this.conn.open(props);

}catch (Exception ex){

System.out.print("ERROR:" + ex.toString());

}

// declare resultset

ResultSet res;

try{

Statement stmt = this.conn.getConn().createStatement();

res = stmt.executeQuery("SELECT categoryid, category FROM categories order by category");

while (res.next()){

try{

this.categoryList.add(new SelectItem(res.getInt("categoryid"),res.getString("category")));

}catch(Exception e){

}

}

}catch (Exception ex){

System.out.print("ERROR" + ex.toString());

}

// close connection

try{

this.conn.close();

}catch (Exception ex){

System.out.print("ERROR" + ex.toString());

}

return this.categoryList;

}

publicvoid setCategoryList(List categoryList){

this.categoryList = categoryList;

}

...

publicvoid loadAssetList(){

//open connection

try{

Properties props =new Properties();

props.load(new FileInputStream("c:/projects/properties/oracle.properties"));

this.conn.open(props);

}catch (Exception ex){

System.out.print("ERROR:" + ex.toString());

}

// declare resultset

ResultSet res;

try{

Statement stmt = this.conn.getConn().createStatement();

res = stmt.executeQuery("SELECT asset, typeid FROM assettypes WHERE category = '" + this.categoryid +"' ORDER BY asset");

int count = 0;

while (res.next()){

this.assetList.add(new SelectItem(res.getInt("typeid"),res.getString("asset")));

}

}catch (Exception ex){

System.out.print("ERROR" + ex.toString());

}

// close connection

try{

this.conn.close();

}catch (Exception ex){

System.out.print("ERROR" + ex.toString());

}

}

public List getAssetList(){

loadAssetList();// Reload to get most recent data.

// return datalist

return this.assetList;

}

publicvoid setAssetList(List assetList){

this.assetList = assetList;

}

...

publicint getCategoryid(){

return categoryid;

}

publicvoid setCategoryid(int categoryid){

this.categoryid = categoryid;

}

[8365 byte] By [bonemachinea] at [2007-11-14]