0

I have a selectOneMenu element(carType) which populates another selectOneMenu(manufacture) element on changing it. This works fine and I get it rendered everytime.

Then I have another selectOneMenu(model) which gets populated evertime the manufacture list is changed. This does not seem to work however.I see that the listener is not called at all for carManufacturerChanged. Any help will be appreciated. Code is :

<p:selectOneMenu value="#{createControler.carType}">
    <f:selectItem itemLabel="Select Car Type" itemValue="" />
    <f:selectItems value="#{createControler.carTypeList}" var="carType"
        itemLabel="#{carType}" itemValue="#{carType}"/>
    <f:ajax event="change" listener="#{createControler.carTypeChanged}" render="manufacture"/>
</p:selectOneMenu><br></br><br></br>

<p:selectOneMenu value="#{createControler.carManufacturer}" id="manufacture">
    <f:selectItem itemLabel="Select Car Manufacturer" itemValue="" />
    <f:selectItems value="#{createControler.carManufacturerList}" var="carManufacturer"
        itemLabel="#{carManufacturer.manufacture}" itemValue="#{carManufacturer.manufacture}"/>
    <f:ajax event="change" listener="#{createControler.carManufacturerChanged}" render="model" />
</p:selectOneMenu><br></br><br></br>

<p:selectOneMenu value="#{createControler.carModel}" id="model">
    <f:selectItem itemLabel="Select Car Model" itemValue="" />
    <f:selectItems value="#{createControler.carModelList}" var="carModel"
        itemLabel="#{carModel.model}" itemValue="#{carModel.model}"/>
</p:selectOneMenu><br></br><br></br>

EDIT : When I add another <f:selectItem itemValue="random" itemLabel="random" /> in the carManufacturer menu, and select it, then the listener is called. So, I think the problem might be that listener is not triggered for elements that are rendered in runtime. Might be of help to someone who can answer.

codeKNIGHT
  • 63
  • 1
  • 8
  • Can you try with `` instead of ``? It would look like this for `manufacture`: `` and listener signature is `public carManufacturerChanged(final AjaxBehaviorEvent event) {...}` – Predrag Maric Nov 20 '14 at 09:30
  • @PredragMaric : Thanks for the comment. I tried it, doesnt help. – codeKNIGHT Nov 20 '14 at 09:53
  • This is just a guess, but try changing the name of the `var` (to something that doesn't clash with another scoped object) in the `f:selectItems` for `model`. Also look in the network tab of the javascript console for clues – kolossus Nov 20 '14 at 20:47
  • @kolossus : No, changing the var name doesnt help either. I dont find any suspicious thing in network tab. The problem is that listener is simply not called. – codeKNIGHT Nov 21 '14 at 02:30

1 Answers1

0

Go check you corresponding CDI bean's scope. If it's RequestScoped, change the scope to ViewScoped or scopes that spans multiple requests.

holyloop
  • 1
  • 1
  • 1