JSF AJAX Update Guidelines
Critical Rules
- •AJAX UPDATE RULE: NEVER use plain HTML elements (div, span) with id attributes for AJAX updates - use JSF components (
h:panelGroup,p:outputPanel) instead - •RENDERED ATTRIBUTE RULE: NEVER use
renderedon plain HTML elements - JSF ignores it; useh:panelGroup layout="block"instead - •COMPONENT REFERENCES: Use
p:resolveFirstComponentWithIdfor updates:update=":#{p:resolveFirstComponentWithId('componentId',view).clientId}" - •NO CSS/jQuery SELECTORS: NEVER use
@(.class),@(#id),@parentinupdateorprocessattributes. Use@this,@form, explicit IDs, or:#{p:resolveFirstComponentWithId(...)}
Wrong vs Correct
xhtml
<!-- WRONG - Plain HTML, AJAX silently fails -->
<div id="stockSelection">
<!-- content -->
</div>
<p:commandButton update="stockSelection" />
<!-- CORRECT - JSF component, AJAX works -->
<h:panelGroup id="stockSelection">
<div><!-- content --></div>
</h:panelGroup>
<p:commandButton update="stockSelection" />
Updating Growl/Messages
The growl component is in template.xhtml outside forms. Use absolute ID with colon prefix:
xhtml
<!-- CORRECT -->
<p:commandButton action="#{bean.save}" update="myTable :growl" />
<!-- WRONG - Do NOT use CSS selectors -->
<p:commandButton update="@(.ui-growl)" />
JSF Components for AJAX Updates
- •
h:panelGroup- Lightweight wrapper, no HTML output - •
p:outputPanel- PrimeFaces panel, renders as<span>or<div> - •
h:div- Renders as HTML<div> - •
h:form- For updating entire form sections - •
p:panel- Full-featured panel with header/footer
Debugging
- •Check browser console for JavaScript errors
- •Verify target element is a JSF component (not plain HTML)
- •Use browser dev tools to confirm JSF-generated id
- •Test with
h:panelGroupwrapper if updates fail - •Check component hierarchy - nested components affect id resolution
For complete reference, read developer_docs/jsf/ajax-update-guidelines.md.