I have a selectrow datatable. After a selection, dialog is appear. There are one input field and 2 outputfield in the dialog. User can edit the input field.
After the edit, user press the update button.
However the update is not performed and there is a error msg.
ARNING: /index.xhtml @208,116 value="#{productDataTableBean.selectedProduct.category}": Target Unreachable, 'null' returned null
javax.el.PropertyNotFoundException: /index.xhtml @208,116 value="#{productDataTableBean.selectedProduct.category}": Target Unreachable, 'null' returned nul
What is the cause of the error? How can i resolve it? Below is the code
xhtml
Code: Select all
<p:panel>
<p:dataTable var="product" value="#{productDataTableBean.products}" paginator="true" rows="10" selectionMode="single" selection="#{productDataTableBean.selectedProduct}" dynamic="false"
update="display1" onselectComplete="productDialog1.show()" widgetVar="productsTable">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields:" />
<h:inputText id="globalFilter" onkeyup="productsTable.filter()" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column sortBy="#{product.modelNumber}" filterBy="#{product.modelNumber}" >
<f:facet name="header">
<h:outputText value="Model" />
</f:facet>
<h:outputText value="#{product.modelNumber}" />
</p:column>
<p:column sortBy="#{product.category}" filterBy="#{product.category}" >
<f:facet name="header">
<h:outputText value="Category" />
</f:facet>
<h:outputText value="#{product.category}" />
</p:column>
<p:column sortBy="#{product.description}" filterBy="#{product.description}" >
<f:facet name="header">
<h:outputText value="Description" />
</f:facet>
<h:outputText value="#{product.description}" />
</p:column>
</p:dataTable>
<p:dialog header="Product Detail" widgetVar="productDialog1"
modal="true" draggable="false" width="500">
<h:panelGrid id="display1" columns="2">
<h:outputText value="Model:" />
<h:outputText value="#{productDataTableBean.selectedProduct.modelNumber}" style="font-weight:bold"/>
<h:outputText value="Category:" />
<p:inplace>
<h:inputText value="#{productDataTableBean.selectedProduct.category}" style="font-weight:bold" id="category1" />
</p:inplace>
<h:outputText value="Description:" />
<h:outputText value ="#{productDataTableBean.selectedProduct.description}" />
<p:commandButton value="Save"
oncomplete="productDialog1.hide();" actionListener="#{productDataTableBean.updateProduct}"
/>
</h:panelGrid>
</p:dialog>
</p:panel>
backing bean
Code: Select all
@ManagedBean(name = "productDataTableBean")
@RequestScoped
public class ProductDataTableBean {
@EJB
private ProductSessionBean productSessionBean;
private Product selectedProduct;
private List<Product> products = new ArrayList<Product>();
private String modelNumber;
private String description;
private String category;
@PostConstruct
public void loadDefaults() {
for (Object o : productSessionBean.getAllProduct()) {
Product le = (Product) o;
products.add(new Product(le.getModelNumber(), le.getDescription(), le.getCategory()));
}
}
public Product getSelectedProduct() {
return selectedProduct;
}
public void setSelectedProduct(Product selectedProduct) {
this.selectedProduct = selectedProduct;
}
public List<Product> getProducts() {
return products;
}
public String getModelNumber() {
return modelNumber;
}
public void setModelNumber(String modelNumber) {
this.modelNumber = modelNumber;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public void updateProduct(ActionEvent product) {
productSessionBean.updateProduct(modelNumber, category);
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Product Updated Successfully", " (Product category is " + category+ ")");
FacesContext.getCurrentInstance().addMessage(null, message);
}
Thank in advance for helping me.