【问题标题】:f:ajax doesn't render DataTable with a value choosen from selectOneMenu [duplicate]f:ajax 不会使用从 selectOneMenu [重复] 中选择的值呈现 DataTable
【发布时间】:2019-01-05 12:04:35
【问题描述】:

我正在尝试使用<f:selectOneMenu> 根据先前选择的值显示数据表。 DataTable 没有被渲染,我也试过<f:ajax render="tabella"> 或者没有panelGroup 或者指定事件或执行但它没有工作。我不知道如何解决它。代码如下:

   <!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>

【问题讨论】:

    标签: ajax jsf xhtml


    【解决方案1】:

    我认为没有添加监听器。所以你可以这样做:

    1. 向 marcaController 添加新方法,例如 'public void doChangeXX()'
    2. 替换

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

    希望对您有所帮助。

    【讨论】:

    • 嗨,我试过了,但似乎没有调用该方法,因为它里面的打印没有显示在控制台上。我也不知道这个方法到底是什么句柄。
    • 您能否在代码中显示 doChangeXX 函数,它应该更新 marca.prodotti 对象以更改表“tabella”。
    • 不需要监听器...
    • 查看BalusC的答案:stackoverflow.com/questions/6089924/…
    猜你喜欢
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多