Update a component that is in another form

Asked

Viewed 1,763 times

3

Hello!

Guys, I made a dialog that inserts fields into a list. This list fills in the values of a selectOneMenu, which is in another form:

<h:form id="idFormDadosTeatro"> 
            <p:panel id="painelTeatro" header="Dados da Teatro"
                style="margin-bottom:20px">
                <h:panelGrid id="painelGridTeatro" columns="2" cellpadding="10">

                        <p:selectOneMenu id="idmotivoDaPecaTeatro"
                            value="#{TeatroBean.idPerfil}" filter="true" required="true"
                            style="width: 226px;margin:5px;"
                            requiredMessage="Campo Motivo da Peça de Teatro é obrigatório"
                            widgetVar="motivo">
                            <f:selectItem itemLabel="Selecione" itemValue=""></f:selectItem>
                            <f:selectItems value="#{TeatroBean.listaDePerfisSelectItem}"></f:selectItems>

                        </p:selectOneMenu>

                        <p:outputLabel value="" style="color: #FF0000"></p:outputLabel>
                        <p:commandLink value="Cadastrar novo motivo de Teatro"
                            onclick="dialogcadastro.show();" />

                </h:panelGrid>
            </p:panel>

            <h:form>
                <p:dialog id="iddialogcadastro"
                    header="Cadastro de Motivo de Teatro" widgetVar="dialogcadastro"
                    resizable="false" appendTo="@form">
                    <h:panelGrid columns="2" cellpadding="5">

                        <h:outputLabel for="nome" value="Nome:" />
                        <p:inputText value="#{TeatroBean.nomeNovoPerfil}" id="nome"
                            required="true" label="nome" immediate="true" />

                        <p:commandButton id="cadastrousuario" value="Cadastrar"
                            actionListener="#{TeatroBean.salvarMotivoTeatro}"
                            oncomplete="PF('dialogcadastro').hide();" process="@form">
                            update=":idFormDadosTeatro:painelTeatro:painelGridTeatro:idmotivoDaPecaTeatro"
                        </p:commandButton>

                    </h:panelGrid>
                </p:dialog>
            </h:form>
        </h:form>

I tried to update this selectOneMenu, but I get the message:

Cannot find component with expression "painelTeatro:painelGridTeatro:idmotivoDaPecaTeatro" referenced from "formGeral:idFormDadosVisita:j_idt76:cadastrousuario".

How could I update the list of this selectOneMenu without the user having to give F5 on the page? Thank you!

  • Note that you have a component without id (j_idt76) you need to find this component and set an id for it

  • @Diegoaugusto, thank you for answering. Well, initially I also thought that was it, so I put id on all the Rms that make up my page (form > panel > panelGrid > selectOneMeu), but the id search only occurs in the dialog iframe. Actually, I wanted a way to get the id search inside the main iframe.

  • Ah, I got it! Silly error. Just add "formGeral" in update=":formGeral:idFormDadosTeatro:idmotiveDaPecaTeatro".

  • Oops, good. You can answer your question and put the solution to the error, this way you will help other people.

  • @Alessandra just a remark that tbm learned recently, in such cases you can break the inheritance of ids that comes by default from the primefaces. For this you could use in your form the attribute "prependId="false". It makes the control much easier most of the time :)

  • @Phelipegaliotti, I will try to use this tip later. Thank you!

Show 1 more comment

1 answer

1

Solved! Just add "formGeral" in the update of the "Register" dialog button:

<h:form>
            <p:dialog id="iddialogcadastro"
                header="Cadastro de Motivo de Teatro" widgetVar="dialogcadastro"
                resizable="false" appendTo="@form">
                <h:panelGrid columns="2" cellpadding="5">

                    <h:outputLabel for="nome" value="Nome:" />
                    <p:inputText value="#{TeatroBean.nomeNovoPerfil}" id="nome"
                        required="true" label="nome" immediate="true" />

                    <p:commandButton id="cadastrousuario" value="Cadastrar"
                        actionListener="#{TeatroBean.salvarMotivoTeatro}"
                        oncomplete="PF('dialogcadastro').hide();" process="@form">
                        update=":formGeral:idFormDadosTeatro:idmotivoDaPecaTeatro"
                    </p:commandButton>

                </h:panelGrid>
            </p:dialog>
        </h:form>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.