Hi, all. I want to setup 4 level category selectOneMenu. When the first 
category value change, the second category selectItems will change automaticlly 
according to the value of the first category. 

I use QuoteHisSearch to store search infomation:
package com.baida.beans;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.EntityManager;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.log.Log;

@Name("quoteHisSearch")
public class QuoteHisSearch {
        /*
         * search parameters
         */
        
        private Category topCategory;
        private Category secondCategory;
        private Category thirdCategory;
        private Category fourthCategory;
        
        private List topCategories;
        private List secondCategories;
        private List thirdCategories;
        private List fourthCategories;
        
                
        public Category getTopCategory() {
                return topCategory;
        }
        public void setTopCategory(Category topCategory) {
                
                this.topCategory = topCategory;         
        }
        public Category getSecondCategory() {
                        
                return secondCategory;
        }
        public void setSecondCategory(Category secondCategory) {
                this.secondCategory = secondCategory;           
        }
        
        public Category getThirdCategory() {
                
                        
                return thirdCategory;
        }
        public void setThirdCategory(Category thirdCategory) {
                this.thirdCategory = thirdCategory;
                
        }
        public Category getFourthCategory() {
                 
                return fourthCategory;
        }
        public void setFourthCategory(Category fourthCategory) {
                this.fourthCategory = fourthCategory;
        }
        public List getTopCategories() {
                
                return topCategories;
        }
        
        public void setTopCategories(List topCategories) {
                this.topCategories = topCategories;
        }
        
        
        public List getSecondCategories() {
                
                return secondCategories;
        }
        
        public void setSecondCategories(List secondCategories) {
                this.secondCategories = secondCategories;
        }       
        
        public List getThirdCategories() {
                
                return thirdCategories;
        }
        
        public void setThirdCategories(List thirdCategories) {
                this.thirdCategories = thirdCategories;
        }
        
        public List getFourthCategories() {
                
                return fourthCategories;
        }
        
        public void setFourthCategories(List fourthCategories) {
                this.fourthCategories = fourthCategories;
        }       

}

In QuoteHisList.java, I add these two function:
public void updateCategories(){
                quoteHisSearch.setTopCategories(getChildrenCatgorys(null));
                if(quoteHisSearch.getTopCategory() != null)
                        
quoteHisSearch.setSecondCategories(getChildrenCatgorys(quoteHisSearch.getTopCategory()));
                if(quoteHisSearch.getSecondCategory() != null)
                        
quoteHisSearch.setThirdCategories(getChildrenCatgorys(quoteHisSearch.getSecondCategory()));
                if(quoteHisSearch.getThirdCategory() != null)
                        
quoteHisSearch.setFourthCategories(getChildrenCatgorys(quoteHisSearch.getThirdCategory()));
                
        }
        
        public List getChildrenCatgorys(Category category){
                EntityManager entityManager = getEntityManager();
                List children = null;
                if(category == null){
                        children = entityManager.createQuery("from Category 
where category=null").getResultList();
                }else{
                        children = (List)entityManager.createQuery("from 
Category where category=:category")
                                                .setParameter("category", 
category)
                                                .getResultList();               
                }
                if(children == null){
                        children = new LinkedList();
                }
                
                return children;
        }

Then add  in QuoteList.page.xhtml.

QuoteList.xhtml's code is like that:
<s:decorate id="categoryDecoration" template="layout/display.xhtml">
                <ui:define 
name="label">#{messages['category.category']}</ui:define>
                <h:selectOneMenu id="topCategory" 
                                                
value="#{quoteHisList.quoteHisSearch.topCategory}" onchange="submit()">
                  <s:selectItems 
value="#{quoteHisList.quoteHisSearch.topCategories}" 
                                                var="category" 
                                                label="#{category.categoryName}"
                                                
noSelectionLabel="#{messages['common.noSelection']}"
                                hideNoSelectionLabel="false"/>
                  <s:convertEntity/>
                                 
                </h:selectOneMenu>
                <h:selectOneMenu id="secondCategory" 
value="#{quoteHisList.quoteHisSearch.secondCategory}" >
                  <s:selectItems 
value="#{quoteHisList.quoteHisSearch.secondCategories}" 
                                                var="category" 
                                                label="#{category.categoryName}"
                                                
noSelectionLabel="#{messages['common.noSelection']}"
                                hideNoSelectionLabel="false"/>
                  <s:convertEntity/>
                  <a:support event="onselectchange" 
reRender="categoryDecoration"/> 
                </h:selectOneMenu>
                <h:selectOneMenu id="thirdCategory" 
value="#{quoteHisList.quoteHisSearch.thirdCategory}" >              
                  <s:selectItems 
value="#{quoteHisList.quoteHisSearch.thirdCategories}" 
                                                var="category" 
                                                label="#{category.categoryName}"
                                                
noSelectionLabel="#{messages['common.noSelection']}"
                                hideNoSelectionLabel="false"/>
                  <s:convertEntity/>
                  <a:support event="onselectchange" 
reRender="categoryDecoration"/> 
                </h:selectOneMenu>
                
            </s:decorate>


I can get the top categories as well. But when I change the top category, the 
seconde category selectitems will not change. I add log to look what's the 
wrong, I found that the qouteHisSearch.topCategory is always not changed, so 
the method updateCategories() will not change the value of  
quoteHisSearch.secondCategories.

Would you help me to fix this problem?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4044906#4044906

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4044906
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to