Update not working in Dialog

UI Components for JSF
garyyip
Posts: 67
Joined: 25 Aug 2010, 18:55

06 Sep 2010, 21:38

Hi

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.

callahan
Posts: 768
Joined: 27 May 2010, 22:52

06 Sep 2010, 22:29

Does it help if you make the managed bean ViewScoped rather than RequestScoped?

garyyip
Posts: 67
Joined: 25 Aug 2010, 18:55

06 Sep 2010, 22:39

Thk for your time to read my code

I tried viewscoped before. It never give me any error and also no update to the datasource. But the changed valued is remain at the input field.

So viewscoped didn't work. Have you tried to update your datasource using the dialog instead.

If i update my datasource upside the dialog, the datasource reflect the changes. Therefore my update function is working well. However, it cant perform when it is in the dialog. So puzzled

callahan
Posts: 768
Joined: 27 May 2010, 22:52

06 Sep 2010, 22:45

Do you mean that there is no PropertyNotFoundException exception when the managed bean is ViewScoped?

garyyip
Posts: 67
Joined: 25 Aug 2010, 18:55

06 Sep 2010, 22:46

I try to refer to the closest sample which is the editable schedule. It allows to select one date and edit the dialog input. Finally save it. This is something what i wanted. The schedule component changed to the datatable component instead.

http://www.primefaces.org/labs/ui/schedule.jsf

I tried to make the code similar but it still not working. Is there something that i missed?

garyyip
Posts: 67
Joined: 25 Aug 2010, 18:55

06 Sep 2010, 22:48

the no PropertyNotFoundException exception happened when i use the requestScoped

The viewScoped did not update my datasource so i changed to requestedscoped instead but the error pop out

callahan
Posts: 768
Joined: 27 May 2010, 22:52

06 Sep 2010, 23:01

You are getting the PropertyNotFoundException because your dialog will not function correctly with a RequestScoped managed bean. You need to use at least ViewScoped and then determine what's wrong with the dialog.

garyyip
Posts: 67
Joined: 25 Aug 2010, 18:55

06 Sep 2010, 23:24

Alright i will try it tml. If it work i will post the solution here. Thk for your help.

If you happen to encounter this problem or see any solution, pls link me the source.... thk alots

User avatar
samanosuke
Posts: 27
Joined: 10 Aug 2010, 00:05

07 Sep 2010, 18:18

I'm not an expert, so I may be wrong. but I think you should initialize selectedProduct. In the constructor for example.
PrimeFaces-2.2.M1, Facelets, JSF 2.0, GlassFish 3.0.1, Netbeans 6.9, Windows 7

garyyip
Posts: 67
Joined: 25 Aug 2010, 18:55

07 Sep 2010, 21:32

Once again Thk callahan for your golden advise in using the viewscoped session. I managed to solve the problem. My update is working now. The fault is i forget to use back the product selected object as the parameter for my update method.

Thk everyone for the help.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 36 guests