I've been following the @BalusC examples at Creating master-detail table and dialog, how to reuse same dialog for create and edit and Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes, trying to get a small form to edit some data and then persist. But, I can't see the changes reflected in the backing bean when I try to save the data.
I have a simple form that I pre-populate with some data and that I might edit before saving:
<h:form id="productSummaryForm">
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Product name:" />
<p:inputText id="productNameInputText" value="#{editProduct.product.productName}" required="true" requiredMessage="Enter Product Name" size="32">
<p:watermark value="The name of the product" for="productNameInputText"/>
</p:inputText>
<h:outputText value="Output name:" />
<p:inputText id="outputNameInputText" value="#{editProduct.product.outputName}" size="32">
<p:watermark value="Output name" for="outputNameInputText"/>
</p:inputText>
</h:panelGrid>
<h:panelGrid columns="3" styleClass="buttonPanelGrid">
<p:commandButton value="Cancel" immediate="true" action="#{productController.cancel}"/>
<p:commandButton id="saveButton" value="Save" process="@this" immediate="true" action="#{editProduct.saveProduct}"/>
</h:panelGrid>
</h:form>
The controller is:
@Named
@ViewScoped
public class EditProduct implements Serializable {
private Product product; // JPA Entity
@Inject
protected ProductService productService;
public String saveProduct() {
productService.saveProduct(product);
return "/product?faces-redirect=true";
}
}
When I debug on saveProduct()
, any edits I made I've made through UI are not reflected in the product
that I save. I've tried adding the inputText
ids to the process
attribute (for example process="@this outputNameInputText"
), still the changes aren't reflected.
None of the different combinations of attributes I tried on saveButton
have changed anything, which makes me think Product
is the problem: it's a JPA entity. Does that sound right?