Fragment component is used to define automatically partially process and update sections whenever ajax request is triggered by a descandant component. In this example, required input field outside the fragment is ignored and only the contents of the fragment are processed-updated automatically on button click since button is inside the fragment. Fragment makes it easy to define partial ajax process and update without explicitly defining component identifiers.
<div class="card">
<h:form>
<div class="formgrid grid p-fluid">
<div class="field col-12 md:col-6">
<p:outputLabel for="ignored" value="Outside of the fragment"/>
<p:inputText id="ignored" required="true" placeholder="Required field" />
</div>
</div>
<p:divider />
<p:fragment>
<p:autoUpdate/>
<div class="formgrid grid p-fluid">
<div class="field col-12 md:col-6">
<p:outputLabel for="txt" value="Inside of the fragment"/>
<p:inputText id="txt" value="#{fragmentView.text}" placeholder="Fragment Field" />
<small>Value: <h:outputText value="#{fragmentView.text}"/></small>
</div>
</div>
<p:commandButton value="Submit"/>
</p:fragment>
</h:form>
</div>
package org.primefaces.showcase.view.ajax;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
@Named
@RequestScoped
public class FragmentView {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}