JSF does not find component ID

Asked

Viewed 762 times

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, an exception FacesException is launched:

Cannot find Component with Expression "formDois" referenced from "formUm:j_idt185".

How can I solve this problem?

  • The question is very objective, I will try to give a hint on the same level. Try this: update="formUm,:form: formDois"

1 answer

2


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

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

He accepts some rules, like:

  1. @this
  2. @form
  3. @Parent
  4. @all
  5. @None

And others...

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

In your case the rule should be:

update=":formUm, :formDois"

If the CommandButton is inside the formUm then I would be:

update="@form, :formDois"

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

Remembering that his commandButton needs to be inside a form and there can be no form's nested.

Some references:

  1. http://www.primefaces.org/showcase/ui/ajax/search.xhtml
  2. http://blog.primefaces.org/? p=2740

Browser other questions tagged

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