更新动态生成的selectOneMenu

时间:2012-10-09 22:46:00

标签: jsf-2 primefaces

在我的网络应用程序中,我有以下DataTable:

<!-- Exibição da lista de públicos -->
                <p:dataTable id="dtEventos" 
                             value="#{relatoriosBean.listaEventos}"
                             paginator="true" rows="5" 
                             rowsPerPageTemplate="5,10"
                             paginatorPosition="bottom"
                             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             var="atual"
                             emptyMessage="Não há eventos para exibição"
                             rendered="#{relatoriosBean.exibirPainelDados}">

                    <f:facet name="header">
                        Eventos
                    </f:facet>

                    <p:column sortBy="#{atual.nmeEvento}" styleClass="wrap">
                        <f:facet name="header">
                            Nome
                        </f:facet>
                        <p:panelGrid columns="1" 
                                     styleClass="gridNoLine">
                            <h:outputLabel id="olViewNomeEvento" 
                                           value="#{atual.nmeEvento}" 
                                           styleClass="t2"/>
                            <p:separator title="Descrição do evento"/>
                            <p:row>
                                <h:outputLabel value="Início: " styleClass="t2"/>
                                <h:outputLabel value="#{atual.dtaInicioEvento}"/>
                                <h:outputLabel value="Término: " styleClass="t2"/>
                                <h:outputLabel value="#{atual.dtaTerminoEvento}"/>
                            </p:row>
                            <h:outputLabel value="#{atual.dscEvento}" 
                                           styleClass="wrap"/>
                        </p:panelGrid>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            Relatórios
                        </f:facet>
                        <p:panelGrid columns="2" styleClass="gridNoLine">
                            <p:selectOneMenu value="#{relatoriosBean.tipoEventoRelatorioSelecionado}"
                                             required="true"
                                             requiredMessage="Selecione o relatório a ser gerado."
                                             effect="fade">
                                <f:selectItem itemLabel="Selecione um item..." itemValue=""/>
                                <f:selectItems value="#{relatoriosBean.tiposEventoRelatorios}">
                                </f:selectItems>
                            </p:selectOneMenu>
                            <p:commandButton icon="ui-icon-document" 
                                             title="Gerar relatório"
                                             actionListener="#{relatoriosBean.gerarRelatorio}"
                                             update="UPDATE THE SELECTONEMENU OF THE LINE">
                                <f:setPropertyActionListener value="#{atual.idtEvento}"
                                                             target="#{relatoriosBean.idEventoSelecionado}}"/>
                            </p:commandButton>
                        </p:panelGrid>
                    </p:column>
                </p:dataTable>

如您所见,在其中一个数据表列中,我有一个selectOneMenu。在同一列中,我有一个设置了actionListener的按钮。好吧,我想要的是:根据commandButton的点击更新列的selectOneMenu。有办法做到这一点吗?

确定!现在f:setPropertyActionListener没有设置属性eventoSelecionado。这是代码:

<p:dataTable value="#{relatoriosBean.listaEventos}"
                             var="atual">
                    ...

                    <p:column>
                        <f:facet name="header">
                            Relatórios
                        </f:facet>
                        <p:panelGrid columns="2" 
                                     styleClass="gridNoLine">
                            <p:selectOneMenu id="somRelatorios"
                                             value="#{relatoriosBean.relatorioSelecionado}"
                                             required="true"
                                             requiredMessage="Selecione o relatório a ser gerado."
                                             effect="fade">
                                <f:selectItem itemLabel="Selecione um item..." itemValue=""/>
                                <f:selectItems value="#{relatoriosBean.relatorios}">
                                </f:selectItems>
                            </p:selectOneMenu>
                            <p:commandButton id="cbGerarRelatorio"
                                             icon="ui-icon-document" 
                                             title="Gerar relatório"
                                             actionListener="#{relatoriosBean.gerarRelatorio}"
                                             update=":frmRelatorios:opPainelDados"
                                             process="@this somRelatorios"
                                             immediate="true">
                                <f:setPropertyActionListener target="#{relatoriosBean.eventoSelecionado}"
                                                             value="#{atual}"/>
                            </p:commandButton>
                        </p:panelGrid>
                    </p:column>
                </p:dataTable>

在gerarRelatorio动作侦听器中,属性eventoSelecionado将作为null传入。有什么问题?

1 个答案:

答案 0 :(得分:1)

当然,将此id=mySelectOne添加到您的<p:selectOneMenu/><p:commandButton/>,将update属性设置为update="mySelectOne"。但是为了在此ajax更新上获得最佳结果,我强烈建议您将托管bean注释设置为@ViewScoped(如果您尚未这样做)。您的命令按钮在更新结束时应如下所示

     <p:commandButton icon="ui-icon-document" 
                                         title="Gerar relatório"
                                         actionListener="#{relatoriosBean.gerarRelatorio}"
                                         update="mySelectOne">