0

i know that this is quetion is already answered here but i don't know why my code didn't work

i have two list and i want that when the first one changes that's the others update here's my code

<h:selectOneMenu id="e4" styleClass="col-md-5" value="#{categoryModel.selectedMenu}">
    <f:selectItem />
    <f:selectItems value="#{categoryModel.catFinanceVect}" var="catFinance"itemLabel="#{catFinance.designation}" itemValue="#{catFinance.ligne}" />
    <!--  <a4j:ajax event="valueChange" render="e3" execute="@this" />-->
    <f:ajax event="valueChange" execute="@this" render="e3" listener="#{categoryModel.getCatItList}"/>
</h:selectOneMenu>
<div class="col-md-1"></div>
<h:selectOneMenu id="e3" styleClass="col-md-6">
    <f:selectItem />
    <f:selectItems value="#{categoryModel.catItVect}" var="catIt"itemLabel="#{catIt.designation}" itemValue="#{catIt.designation}" />
</h:selectOneMenu>

and here's my backing bean :

@ManagedBean
@SessionScoped
public class CategoryModel {


    private CatFinance catFinance= new CatFinance();
    private Vector<CatFinance> catFinanceVect = new Vector<CatFinance>();
    private CatIt catIt= new CatIt();
    private Vector<CatIt> catItVect = new Vector<CatIt>();
    private Integer selectedMenu;



    public CategoryModel() {
        super();
        // TODO Auto-generated constructor stub
    }


    public CatFinance getCatFinance() {
        return catFinance;
    }


    public void setCatFinance(CatFinance catFinance) {
        this.catFinance = catFinance;
    }


    public Vector<CatFinance> getCatFinanceVect() {
        return catFinanceVect;
    }


    public void setCatFinanceVect(Vector<CatFinance> catFinanceVect) {
        this.catFinanceVect = catFinanceVect;
    }

public CatIt getCatIt() {
        return catIt;
    }


    public void setCatIt(CatIt catIt) {
        this.catIt = catIt;
    }


    public Vector<CatIt> getCatItVect() {
        return catItVect;
    }


    public void setCatItVect(Vector<CatIt> catItVect) {
        this.catItVect = catItVect;
    }



public Integer getSelectedMenu() {
        return selectedMenu;
    }


    public void setSelectedMenu(Integer selectedMenu) {
        this.selectedMenu = selectedMenu;
    }


public void getCatFinanceList(){

        this.setCatFinance(new CatFinance());
        CatFinanceService catFinanceService = (CatFinanceService) SpringDaoCtxFactory.getDaoContext().getBean("CatFinanceService");
        this.getCatFinanceVect().clear();

        try {
            this.getCatFinanceVect().addAll(catFinanceService.getCatFinanceList());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

        public void getCatItList(AjaxBehaviorEvent event){

            this.setCatIt(new CatIt());
            CatItService catItService = (CatItService) SpringDaoCtxFactory.getDaoContext().getBean("CatItService");
            this.getCatItVect().clear();
            System.out.println("aaaa");
            try {
                this.getCatItVect().addAll(catItService.getCatItList(2));
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
@PostConstruct
public void init(){
    getCatFinanceList();
}

}

if anyone can help in this or give me a good tutoriel of how to do it i will appreciate it so much thanks in advance

Anonymous
  • 11,748
  • 6
  • 35
  • 57
melmrini
  • 11
  • 3
  • i had myself a hard time learning about rendering, but balusc answer helped me have you gone through this? [Primefaces SelectOneMenu ajax rendering](http://stackoverflow.com/a/14895021/2819935) – Syed Anas Mar 24 '14 at 04:22
  • thanks for ur answer..no it doesn't work..i think it different because this prblm is for and mine is for – melmrini Mar 24 '14 at 12:29
  • Don't use getter methods as listeners. Getter methods are intended to access properties and they must return a type. Please follow java conventions. Apart from that I suppose you've wraped the components with a `h:form`? – Aritz Mar 24 '14 at 14:13
  • @Laniebla you said it right it was for panelGroup and thats what i did when i was doing in selectOneMenu it did not work when i wrapped it up in a panelGroup it worked. Have you also seen the link provided in balusc answer he explained it very well there i dont wanted to copy paste else i would have done it. – Syed Anas Mar 25 '14 at 04:16
  • @Xtreme Biker thanks for the answer..it's not getter method it's just a name of a method..and yes it's wrapped in h:form – melmrini Mar 25 '14 at 08:15
  • @La niebla, well, it's supposed to methods starting with `get` to be getters. That's why you should rename that. Here it is the documented way to do what you want, see "Populate a child menu": http://stackoverflow.com/tags/selectonemenu/info – Aritz Mar 25 '14 at 08:17
  • @anas..can u please give me how did u make it because i added panelGroup and it didn't work ? – melmrini Mar 25 '14 at 08:33
  • @Xtreme Bike thanks so much it's worked for me..but i just want to know why it creates a new selectOneMenu instead of mine ? p.s : i have predendId=false in h:form – melmrini Mar 26 '14 at 11:20

1 Answers1

1

The f:ajax event is invalid. It should be change (or empty as it defaults to change for h:selectOneMenu.)

<f:ajax execute="@this" render="e3" listener="#{categoryModel.getCatItList}"/>

Simon Arsenault
  • 1,777
  • 17
  • 35