-1

I'm trying to use a <f:selectOneMenu> to show a dataTable based on the previously chosen value. The DataTable doesn't be rendered, I tried also <f:ajax render="tabella"> or without the panelGroup or specifying event or excecute but it didn't works. I don't know how to solve it. Here is the code:

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://java.sun.com/jsf/core"> 

<ui:composition template="/template.xhtml">


    <ui:define name="content">

        <h:form id="form1">
        <h:panelGroup id="pannello" >
            <h:selectOneMenu id="marcaScelta" value="#{marcaController.marca}" >
                <f:selectItem itemLabel="Scegli una marca"/>
                <f:selectItems value="#{marcaController.listaMarche()}" var="m" itemLabel="#{m.nome}" itemValue="#{m.nome}">
                </f:selectItems>
                <f:ajax render="pannello form1" />      
            </h:selectOneMenu>
            <h1 align="center"> Elenco prodotti #{marcaController.marca.nome} </h1>
            <h:dataTable id="tabella"  value="#{marcaController.marca.prodotti}" var="prodotto">

                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Nome" />
                    </f:facet>
                    <h:outputText value="#{prodotto.nome}" />
                </h:column>

                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Prezzo" />
                    </f:facet>
                    <h:outputText value="#{prodotto.prezzo}" />
                </h:column>

                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Quantita" />
                    </f:facet>
                    <h:outputText value="#{prodotto.quantita}" />
                </h:column>

                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Azioni" />
                    </f:facet>
                    <h:commandLink action="#{carrelloController.aggiungiAlCarrello(prodotto)}" value="Aggiungi al Carrello"></h:commandLink>
                </h:column> 
            </h:dataTable>
            </h:panelGroup>
        </h:form>
    </ui:define>
</ui:composition>
</html>
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Albyx97
  • 31
  • 5

1 Answers1

-2

I think that the listner is not added. So you can do:

  1. Add a new method to marcaController, for example 'public void doChangeXX()'
  2. Replace

< f:ajax render="pannello form1" />

With

<f:ajax listener="#{marcaController.doChangeXX}" render="pannello form1" /> 

Hope this help.

Vinh Can Code
  • 407
  • 3
  • 14
  • Hi, I tried but It seems like the method isn't called because the print inside it isn't shown on the console. I also don't know precisely what handle in this method. – Albyx97 Jul 28 '18 at 17:45
  • can you show the doChangeXX function in your code, it should update the marca.prodotti object in order to change the Table "tabella". – Vinh Can Code Jul 28 '18 at 18:09
  • 2
    Listeners are not needed... – Kukeltje Jul 28 '18 at 18:30
  • See the Answer of BalusC: https://stackoverflow.com/questions/6089924/the-fajax-listener-method-in-hselectonemenu-is-not-executed – Vinh Can Code Jul 29 '18 at 01:13