id problem already exists in view

Asked

Viewed 409 times

0

Hello, everyone. I have a . xhtml file that is giving an id error already found in the view. The error itself is

GRAVE: JSF1007: frmPesquisa:id duplicate component ID found in view.

I searched on the internet about this error but the answers I found are relatively vague and I could not use them to solve my problem.

I am posting the file of the xhtl page that is giving problem. I will also post the code of another page that is using the same id (frmPesquisa) and is working.

To strengthen, the page that is giving error is the Search page property.xhtml. The Search page file user.xhtml is for comparison only.

Search property.xhtml

<ui:define name="titulo">Pesquisar Propriedades</ui:define>

<ui:define name="corpo">
    <h:form id="frmPesquisa">
    <p:messages showDetail="false" showSummary="true" autoUpdate="true" />

    <h1>Pesquisa de propriedades</h1>

    <p:toolbar style="margin-top: 20px">
        <p:toolbarGroup>
            <p:commandButton value="Pesquisar" action="#{pesquisaPropriedadeBean.pesquisar}" update="@form" />
            <p:selectOneRadio id="id" value="#{pesquisaPropriedadeBean.filtro.status}" >
                <f:selectItem itemLabel="Ativo" itemValue="Ativo" />
                <f:selectItem itemLabel="Inativo" itemValue="Inativo" />
            </p:selectOneRadio>
        </p:toolbarGroup>
        <p:toolbarGroup align ="right">
            <p:button value="Novo" outcome="/propriedade/CadastroPropriedade"/>
        </p:toolbarGroup>
    </p:toolbar>

    <p:panelGrid columns="2" id="painel" style="width: 100%; margin-top: 20px" columnClasses="rotulo, campo">
        <p:outputLabel value="id" for="id"/>
        <p:inputText id="id" size="60" maxlength="80"
        value="#{pesquisaPropriedadeBean.filtro.propriedadeId}"/>
    </p:panelGrid>

    <p:dataTable id="propriedadesTable"
            value="#{pesquisaPropriedadeBean.propriedadesFiltradas}" var="propriedade"
            style="margin-top: 20px" emptyMessage="Nenhuma propriedade encontrada."
            rows="20" paginator="true" paginatorAlwaysVisible="false"
            paginatorPosition="bottom">

    <p:column headerText="Id" style="text-align: center; width: 100px">
            <h:outputText value="#{propriedade.id}" />
    </p:column>

    <p:column headerText="Nome" style="text-align: center; width: 100px">
            <h:outputText value="#{propriedade.nome}" />
    </p:column>

    <p:column headerText="Proprietário" style="text-align: center; width: 100px">
            <h:outputText value="#{propriedade.usuario}" />
    </p:column>

    <p:column headerText="Área" style="text-align: center; width: 100px">
            <h:outputText value="#{propriedade.area}" />
    </p:column>

    <p:column headerText="matrícula" style="text-align: center; width: 100px">
            <h:outputText value="#{propriedade.matricula}" />
    </p:column>

    <p:column headerText="Estado" style="text-align: center; width: 100px">
            <h:outputText value="#{propriedade.estado}" />
    </p:column>

    <p:column headerText="Cidade" style="text-align: center; width: 100px">
            <h:outputText value="#{propriedade.cidade}" />
    </p:column>

    <p:column headerText="Endereço" style="text-align: center; width: 100px">
            <h:outputText value="#{propriedade.endereco}" />
    </p:column>

    <p:column headerText="Status" style="text-align: center; width: 100px">
            <h:outputText value="#{propriedade.status}" />
    </p:column>

    <p:column headerText="Operações" style="width: 100px; text-align: center">
    <c:set var ="status" scope = "session"/>
            <p:button outcome = "/propriedade/CadastroPropriedade" icon="ui-icon-pencil" title="Editar" disabled ="#{pesquisaPropriedadeBean.inativo}">
                <f:param name="propriedade" value="#{propriedade.id}" />
            </p:button>
            <p:commandButton icon="ui-icon-bloquear" title="Alterar status do cadastro" oncomplete="PF('confirmacaoExclusao').show()" process="@this" update="frmPesquisa:confirmacaoExclusaoDialog">
                <f:setPropertyActionListener value="#{propriedade}" target="#{pesquisaPropriedadeBean.propriedadeSelecionada}"/>    
            </p:commandButton>
    </p:column>


    </p:dataTable>

        <p:confirmDialog header="Alterar status do cadastro"
            message="Tem certeza que deseja alterar o status do cadastro do usuário #{pesquisaUsuarioBean.usuarioSelecionado.nome}?"
            widgetVar="confirmacaoExclusao" id="confirmacaoExclusaoDialog">
            <p:button value="Não"
                onclick="PF('confirmacaoExclusao').hide(); return false;" />
            <p:commandButton value="Sim"
                oncomplete="PF('confirmacaoExclusao').hide();" action="#{pesquisaUsuarioBean.excluir}" process="@this" update="frmPesquisa:propriedadesTable"/>
        </p:confirmDialog>
</h:form>
</ui:define>

Searcher.xhtml.

<ui:define name="titulo">Pesquisar Usuarios</ui:define>

<ui:define name="corpo">
    <h:form id="frmPesquisa">
    <p:messages showDetail="false" showSummary="true" autoUpdate="true" />

    <h1>Pesquisa de usuários</h1>

    <p:toolbar style="margin-top: 20px">
        <p:toolbarGroup>
            <p:commandButton value="Pesquisar" action="#{pesquisaUsuarioBean.pesquisar}" update="@form" />
            <p:selectOneRadio id="id" value="#{pesquisaUsuarioBean.filtro.status}" >
                <f:selectItem itemLabel="Ativo" itemValue="Ativo" />
                <f:selectItem itemLabel="Inativo" itemValue="Inativo" />
            </p:selectOneRadio>
        </p:toolbarGroup>
        <p:toolbarGroup align ="right">
            <p:button value="Novo" outcome="/usuario/CadastroUsuario"/>
        </p:toolbarGroup>
    </p:toolbar>

    <p:panelGrid columns="2" id="painel" style="width: 100%; margin-top: 20px" columnClasses="rotulo, campo">
        <p:outputLabel value="Nome" for="nome"/>
        <p:inputText id="nome" size="60" maxlength="80"
        value="#{pesquisaUsuarioBean.filtro.nome}"/>
    </p:panelGrid>

    <p:dataTable id="usuariosTable"
            value="#{pesquisaUsuarioBean.usuariosFiltrados}" var="usuario"
            style="margin-top: 20px" emptyMessage="Nenhum usuario encontrado."
            rows="20" paginator="true" paginatorAlwaysVisible="false"
            paginatorPosition="bottom">

    <p:column headerText="Id" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.id}" />
    </p:column>

    <p:column headerText="Nome" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.nome}" />
    </p:column>

    <p:column headerText="RG" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.rg}" />
    </p:column>

    <p:column headerText="CPF" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.cpf}" />
    </p:column>

    <p:column headerText="Email" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.email}" />
    </p:column>

    <p:column headerText="Telefone" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.telefone}" />
    </p:column>

    <p:column headerText="Celular" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.celular}" />
    </p:column>

    <p:column headerText="Endereço" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.endereco}" />
    </p:column>

    <p:column headerText="Estado" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.estado}" />
    </p:column>

    <p:column headerText="Cidade" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.cidade}" />
    </p:column>

    <p:column headerText="CEP" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.cep}" />
    </p:column>

    <p:column headerText="Status" style="text-align: center; width: 100px">
            <h:outputText value="#{usuario.status}" />
    </p:column>

    <p:column headerText="Operações" style="width: 100px; text-align: center">
    <c:set var ="status" scope = "session"/>
            <p:button outcome = "/usuario/CadastroUsuario" icon="ui-icon-pencil" title="Editar" disabled ="#{pesquisaUsuarioBean.inativo}">
                <f:param name="usuario" value="#{usuario.id}" />
            </p:button>
            <p:commandButton icon="ui-icon-bloquear" title="Alterar status do cadastro" oncomplete="PF('confirmacaoExclusao').show()" process="@this" update="frmPesquisa:confirmacaoExclusaoDialog">
                <f:setPropertyActionListener value="#{usuario}" target="#{pesquisaUsuarioBean.usuarioSelecionado}"/>    
            </p:commandButton>
    </p:column>


    </p:dataTable>

        <p:confirmDialog header="Alterar status do cadastro"
            message="Tem certeza que deseja alterar o status do cadastro do usuário #{pesquisaUsuarioBean.usuarioSelecionado.nome}?"
            widgetVar="confirmacaoExclusao" id="confirmacaoExclusaoDialog">
            <p:button value="Não"
                onclick="PF('confirmacaoExclusao').hide(); return false;" />
            <p:commandButton value="Sim"
                oncomplete="PF('confirmacaoExclusao').hide();" action="#{pesquisaUsuarioBean.excluir}" process="@this" update="frmPesquisa:usuariosTable"/>
        </p:confirmDialog>
</h:form>
</ui:define>

Thanks in advance for any suggestions, opinions or advice.

2 answers

1

JSF doesn’t allow you to have equal id’s, so what you need to do is change it from one of the pages you posted. I recommend you detail more the id, something like and ....

  • Exact, namecontainers should be unique, complementing your answer: doc The specified identifier must be unique among all the components (including facets) that are descendents of the nearest ancestor UIComponent that is a NamingContainer, or within the scope of the entire component tree if there is no such ancestor that is a NamingContainer.

  • But the question is this: I have in total 4 pages that are using the same id (frmPesquisa) and the other 3 pages are not giving this error.

0

Within the same form you are using twice the same id="id". And this cannot. Note from the other form to which you mentioned that it works, you don’t have twice the same.

Below the snippets with duplicate ID.

<p:toolbar style="margin-top: 20px">
        <p:toolbarGroup>
            <p:commandButton value="Pesquisar" action="#{pesquisaPropriedadeBean.pesquisar}" update="@form" />
            <p:selectOneRadio id="id" value="#{pesquisaPropriedadeBean.filtro.status}" >
                <f:selectItem itemLabel="Ativo" itemValue="Ativo" />
                <f:selectItem itemLabel="Inativo" itemValue="Inativo" />
            </p:selectOneRadio>
        </p:toolbarGroup>
        <p:toolbarGroup align ="right">
            <p:button value="Novo" outcome="/propriedade/CadastroPropriedade"/>
        </p:toolbarGroup>
    </p:toolbar>

    <p:panelGrid columns="2" id="painel" style="width: 100%; margin-top: 20px" columnClasses="rotulo, campo">
        <p:outputLabel value="id" for="id"/>
        <p:inputText id="id" size="60" maxlength="80"
        value="#{pesquisaPropriedadeBean.filtro.propriedadeId}"/>
    </p:panelGrid>

Browser other questions tagged

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