2

I have this div

<div id="name">
    ....
</div>

I also have a button that does this:

<h:commandLink id="bttn" action="#">
    <f:ajax render="name"/>
</h:commandLink>

The problem is that when executing, it says that there is no component called "name". Is there a way I can render a div with an ajax without enclosing it within a jsf component?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Nacho321
  • 1,911
  • 7
  • 33
  • 55

1 Answers1

5

No, there's no way. Ajax rendering works roughly as follows under JSF's hoods:

for (String clientIdToRender : clientIdsToRender) {
    UIComponent componentToRender = viewRoot.findComponent(clientIdToRender);
    // ...
}

However, as the plain HTML <div> is not as a fullworthy JSF component available by UIViewRoot#findComponent(), JSF can't find anything to generate the updated HTML output for.

You do not necessarily need to wrap it in another JSF component, you can also just use a JSF component which generates already a HTML <div> element. That is the <h:panelGroup> component whose layout attribute is set to block (as in, "render a block level element").

<h:panelGroup layout="block" id="name">
    ...
</h:panelGroup>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555