Nacho321
Nacho321

Reputation: 1991

Rendering a div with ajax

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?

Upvotes: 2

Views: 7248

Answers (1)

BalusC
BalusC

Reputation: 1108642

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:

Upvotes: 5

Related Questions