Jsf 2 更新动态生成的SelectOne菜单
在我的web应用程序中,我有以下数据表:Jsf 2 更新动态生成的SelectOne菜单,jsf-2,primefaces,Jsf 2,Primefaces,在我的web应用程序中,我有以下数据表: <!-- Exibição da lista de públicos --> <p:dataTable id="dtEventos" value="#{relatoriosBean.listaEventos}" paginator="true" rows="5"
<!-- 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>
事件
诺姆
雷拉托里奥斯酒店
如您所见,在一个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。有什么问题吗?当然,将此
id=mySelectOne
添加到您的
中,并在
上设置update
属性为update=“mySelectOne”
。但是为了在这次ajax更新中获得最佳效果,我强烈建议您将托管bean注释设置为@ViewScoped
,如果您还没有这样做的话。更新结束时,您的命令按钮应该如下所示
<p:commandButton icon="ui-icon-document"
title="Gerar relatório"
actionListener="#{relatoriosBean.gerarRelatorio}"
update="mySelectOne">
@mnatan.brito当然可以,但从技术上讲,这是一个问题,所以您可能应该删除它并作为单独的问题重新发布