JSF does not find component ID

1

I have something like

<p:panelGrid id="tabelaUm">
    <h:form id="formUm" rendered="#{condicao ? true : false}"/>
    <p:commandButton action="#{condicao = false}" update="formUm, formDois"/>
</p:panelGrid>
<p:panelGrid id="tabelaDois">
    <h:form id="formDois" rendered="#{condicao ? false : true}"/>
</p:panelGrid>

When I try to access the page, a FacesException exception is thrown:

  

Can not find component with expression "formDois" referenced from "formUm: j_idt185".

How can I resolve this problem?

    
asked by anonymous 15.11.2014 / 16:51

1 answer

2

Because you are in different forms, CommandButton and formDois , the Search Expression you used is not valid.

The Search Expression Framework is the framework that Primefaces uses to find components in the tree, either through the process or the update attribute.

It accepts some rules, such as:

  • @this
  • @form
  • @parent
  • @all
  • @none
  • And others ...

    In addition to some modifiers like the ":", which defines the hierarchy.

    In your case the rule should be:

    update=":formUm, :formDois"
    

    If CommandButton is within formUm then it would look like:

    update="@form, :formDois"
    

    Putting the ":" at the beginning means that it is to start the search from ViewRoot .

    Remembering that your commandButton must be within form and there can not be form's nested.

    Some references:

  • link
  • link
  • 15.11.2014 / 18:52