0

I have this HTML:

<ui:composition template="/templates/layout.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:jsf="http://xmlns.jcp.org/jsf"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:p="http://xmlns.jcp.org/jsf/passthrough">

    <ui:define name="titulo">Cadastro</ui:define>

    <ui:define name="conteudo">
        <div>
            <h:selectOneMenu id="setores" value="#{pagCadastro.setor}" valueChangeListener="#{pagCadastro.aoMudarSetor}">
                <f:selectItems value="#{pagCadastro.setores}" />
            </h:selectOneMenu>

            <fieldset jsf:rendered="#{pagCadastro.setor.id >= 1}">
                <legend>E-mails dos Grupos</legend>

                <h:commandLink id="novo" value="Novo" title="Inclui um novo e-mail de grupo" rendered="#{pagCadastro.estado == 'CONSULTA'}" action="#{pagCadastro.novo}" />

                <h:dataTable id="emailsGruposSetor" value="#{pagCadastro.emailsGruposSetor}" var="email" rendered="#{!empty pagCadastro.emailsGruposSetor}">
                    <h:column>
                        <h:outputText value="#{email}" rendered="#{email != pagCadastro.emailGrupoEmEdicao}" />
                        <h:inputText value="#{email}" rendered="#{email == pagCadastro.emailGrupoEmEdicao}" p:autofocus="true" />
                    </h:column>
                    <h:column>
                        <h:commandLink value="Editar" rendered="#{pagCadastro.estado == 'CONSULTA'}" action="#{pagCadastro.editar(email)}">
                            <f:ajax render="form:novo form:emailsGruposSetor" />
                        </h:commandLink>
                        <h:commandLink value="Salvar" rendered="#{email == pagCadastro.emailGrupoEmEdicao}" />
                        <h:commandLink value="Cancelar" rendered="#{email == pagCadastro.emailGrupoEmEdicao}" title="Cancela a edição" action="#{pagCadastro.cancelar}" />
                        <h:commandLink value="Excluir" rendered="#{pagCadastro.estado == 'CONSULTA' || (pagCadastro.estado == 'EDICAO' and email == pagCadastro.emailGrupoEmEdicao)}" />
                    </h:column>
                </h:dataTable>

                <h:outputText id="nenhumEmailGrupoEncontrado" value="Nenhum e-mail de grupo encontrado." rendered="#{empty pagCadastro.emailsGruposSetor}" />
            </fieldset>
        </div>
    </ui:define>
</ui:composition>

but when the command link with value "Editar" is clicked, only the data table is rendered when the ajax call returns, not the command link with id novo.

If I wrap the command link novo and the data table emailsGruposSetor with a panel group and specify the id of the panel group in the ajax tag for rendering, both the command link and the data table are rendered as expected. Also, If I don't specify the form id in the ajax render attribute for the components, nothing is rendered, including the data table.

What am I doing wrong?

Here's the layout.xhtml with the form:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:jsf="http://xmlns.jcp.org/jsf"
      xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions">
      <ui:insert name="metadados" />
      <h:head>
        <title>Grupos de E-mail de Servidores</title>
        <h:outputStylesheet library="css" name="gruposemailservidores.css" />
        <h:outputScript library="script" name="jquery.js" />
        <h:outputScript library="script" name="gruposemailservidores.js" />
        <ui:insert name="importacoes" />
        <h:outputStylesheet library="css" name="#{fn:substring(view.viewId, 1, fn:indexOf(view.viewId, '.'))}.css" />
        <h:outputScript library="script" name="#{fn:substring(view.viewId, 1, fn:indexOf(view.viewId, '.'))}.js" />
      </h:head>
      <h:body>
        <div id="cabecalho">
            <img src="resources/img/ufca.png" alt="..." />
            <span>Grupos de E-mail de Servidores</span>
        </div>

        <h:form id="form">
            <div jsf:id="titulo" jsf:rendered="#{view.viewId != '/login.xhtml'}">
                <ui:insert name="titulo" />
            </div>

            <div id="conteudo">
                <ui:insert name="conteudo" />
            </div>
        </h:form>

        <div id="rodape">
        </div>
      </h:body>
</html>

UPDATE:

The suggested answer here How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar" doesn't solve my problem.

Community
  • 1
  • 1
Marcos
  • 1,237
  • 1
  • 15
  • 31
  • Please create an [mcve] and also read [ask]. You talk about a form but there is no form visible. – Kukeltje Oct 29 '15 at 13:20
  • I updated the question to include the form. – Marcos Oct 29 '15 at 13:25
  • @BalusC the client id of the component is `form:novo` (I've already checked it in the raw HTML), so why it is not rendered if I'm specifying the right id in the ajax tag (`render="form:novo form:emailsGruposSetor"`)? – Marcos Oct 29 '15 at 13:33
  • @BalusC Here´s the generated HTML for the component: `Novo` – Marcos Oct 29 '15 at 13:35
  • Read answer in duplicate from top to bottom, it clearly says to prefix with `:` like so `render=":form:novo"` (and do F5, I just updated it to save souls like you ;) ) – BalusC Oct 29 '15 at 13:41
  • @BalusC I regret to say that it didn't work (FYI, I'd already tried it before posting this question here). And using the the attribute like this ``, even the data table doesn´t get rendered. As you can see, I'm still _'lost'_ :-) – Marcos Oct 29 '15 at 13:49
  • I recommend to fix your question to show the problem in MCVE format. There's too much noise in the code, among others `rendered="#{pagCadastro.setor.id >= 1}"` which may possibly cause the same experience. See also http://stackoverflow.com/tags/jsf/info – BalusC Oct 29 '15 at 13:53
  • I had already removed the `fieldset` tag before just to test because I was supecting about it but the problem remained. In my opinion, I'm not doing anything wrong here. This is just a plain bug in JSF for some reason. I'm using _Wildfly 8.2.0_ with all default libraries that come with it. I agree that the code I posted is noise, but I think that it's not too hard to ignore the irrelevant parts and concentrate only on the two links and the table. Thank you for the help. – Marcos Oct 29 '15 at 14:06

0 Answers0