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 changing *every 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
********************

        private int categoryid;
        private int assetType;
  private List categoryList = new ArrayList();
        private List assetList = new ArrayList();
        
        ....
        
                public void 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;
        }
        
        public void setCategoryList(List categoryList) {
                this.categoryList = categoryList;
        }

        
        ...
        
                public void 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;
        }

        public void setAssetList(List assetList) {
                this.assetList = assetList;
        }

        ...
        
                public int getCategoryid() {
                        return categoryid;
                }

        public void setCategoryid(int categoryid) {
                this.categoryid = categoryid;
        }

        
        
-- 
View this message in context: 
http://www.nabble.com/Drop-down-menu-value-not-updating-consistently-in-backing-bean-tf3494297.html#a9759895
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Reply via email to