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>
<p:inputText id="ignored" required="true" placeholder="Required field" />
<p:divider />
<p:fragment>
<p:autoUpdate/>
<h:panelGrid columns="4" cellpadding="7">
<p:inputText id="txt" value="#{fragmentView.text}" placeholder="Fragment Field" />
<p:commandButton value="Submit"/>
<h:outputText value="#{fragmentView.text}"/>
</h:panelGrid>
</p:fragment>
</h:form>
</div>
package org.primefaces.showcase.view.ajax;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named
@RequestScoped
@RegisterForReflection(serialization = true)
public class FragmentView {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}