problems clearing a p:dialog

UI Components for JSF
Post Reply
rcowart
Posts: 1
Joined: 27 Jan 2011, 16:28

28 Jan 2011, 17:58

I have a simple datatable wich allows the users to browse records in a db table, when I click the add button, I am showing a p:dialog control to allow the user to create a new db record. The problem is is a user selected a record to view or edit first by clicking on a row in the dataTable, I am not able to clear the field values on the dialog. No matter what I do I can't clear the p:dialog field vlaues.
Here is my xhtml page

Code: Select all

 

.....

    <h:body>
        <f:view>
          <h:form>

             Hello from Facelets<br></br>
             test prop: #{cITrackerBean.testProperty}

             <p:dataTable var="ci" value="#{cITrackerBean.ciList}"
                          paginator="true" rows="10"
                          selection="#{cITrackerBean.selectedCI}" selectionMode="single"
                          rowSelectListener="#{cITrackerBean.onRowSelect}"
                          update="dlg"
                          onRowSelectComplete="ciDialog.show()" >
                          


                 <f:facet name="header">
                    CI Tracker
                 </f:facet>

                 <p:column>
                     <f:facet name="header">
                         Date
                     </f:facet>
                     #{ci.dateSubmitted}
                 </p:column>

                 <p:column>
                     <f:facet name="header">
                         User
                     </f:facet>
                     #{ci.userId}
                 </p:column>
                 

                 <p:column>
                     <f:facet name="header">
                         Recommendation
                     </f:facet>
                     #{ci.recommendation}
                 </p:column>

                 <f:facet name="footer">
                    <h:panelGrid columns="2">
                      <h:outputText value="Click on A Row To View or Edit"  />
                      <p:commandButton value="Add" action="#{cITrackerBean.clearData}" update="grid2" oncomplete="ciDialog.show()" />
                    </h:panelGrid>
                </f:facet>


             </p:dataTable>

 

             <p:dialog id="dlg" header="Add/Edit" widgetVar="ciDialog" resizable="false" modal="true" width="1000"  >

                 <h:panelGrid id="grid1" columns="3" >
                     <h:outputLabel value="User" for="user" />
                     <h:inputText id="user" value="#{cITrackerBean.selectedCI.userId}" size="30" maxlength="30" />
                     <p:commandButton value="Save" action="#{cITrackerBean.updateDatabase}" oncomplete="ciDialog.hide()" />
                 </h:panelGrid>

                 <h:panelGrid id="grid2" columns="2">

                     <p:panel header="Recommendation (Summary)">
                         <h:inputTextarea id="rec" value="#{cITrackerBean.selectedCI.recommendation}" rows="4" cols="25" />
                     </p:panel>

                     <p:panel header="Type Of Improvement Idea">
                         <h:selectOneRadio value="#{cITrackerBean.selectedCI.typeId}" layout="pageDirection">
                             <f:selectItems value="#{cITrackerBean.typeList}" var="i"
                                            itemLabel="#{i.name}"  itemValue="#{i.typeId}" />
                         </h:selectOneRadio>
                     </p:panel>

                       <p:panel header="Functional Area Of Improvement">
                           <h:selectManyCheckbox   value="#{cITrackerBean.areaValueSelectList}" layout="pageDirection">
                               <f:selectItems value="#{cITrackerBean.areaList}" var="j"
                                              itemLabel="#{j.name}" itemValue="#{j.id}"/>
                           </h:selectManyCheckbox>
                       </p:panel>

                     <p:panel header="Recommendation (Summary)">
                         <h:inputTextarea id="det" value="#{cITrackerBean.selectedCI.detail}" rows="20" cols="50" />
                     </p:panel>


                 </h:panelGrid>
             </p:dialog>

          </h:form>
        </f:view>

    </h:body>
.......
Below is my managed bean code

Code: Select all



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.snf.ManagedBeans;

import com.snf.DTO.AreaDTO;
import com.snf.DTO.AreaValueDTO;
import com.snf.DTO.CIDTO;
import com.snf.DTO.TypeDTO;
import com.snf.SessionBeans.SQLBeanLocal;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;
import org.primefaces.event.SelectEvent;

/**
 *
 * @author rcowart
 */
@ManagedBean
@ApplicationScoped
public class CITrackerBean
{
    @EJB
    private SQLBeanLocal sqlBean;


    List<CIDTO> ciList;
    List<TypeDTO> typeList;
    List<AreaValueDTO> areaValueList;
    List<AreaDTO> areaList;
    ArrayList<Long> areaValueSelectList;
    CIDTO selectedCI = new CIDTO();
    String testProperty = "test";



    /** Creates a new instance of CITrackerBean */
    public CITrackerBean()
    {
      
    }
    
    @PostConstruct
    private void init()
    {
      System.out.println("calling init method");

      ciList = sqlBean.getAllCI();
      typeList = sqlBean.getAllType();
      areaList = sqlBean.getAllArea();


    }

    public void onRowSelect(SelectEvent event)
    {
       System.out.println("calling onRowSelect");

       //selectedCI = (CIDTO)event.getObject();

       System.out.println("CIDTO recomendation: " + selectedCI.getRecommendation());
       System.out.println("CIDTO detail: " + selectedCI.getDetail());
       //return "CITrackerUpdate?faces-redirect=true";

       this.areaValueSelectList = sqlBean.getSelectedAreaValueByCiId(selectedCI.getCiId());
    }

    public void updateDatabase()
    {
        System.out.println("calling updateDatabase");
    }

    public void clearData()
    {
        System.out.println("calling clearData");

        this.areaValueSelectList = new ArrayList();
        this.selectedCI = new CIDTO();
    }

    public String getTestProperty()
    {
        return testProperty;
    }

    public void setTestProperty(String testProperty)
    {
        this.testProperty = testProperty;
    }

    public List<CIDTO> getCiList()
    {
        return ciList;
    }

    public void setCiList(List<CIDTO> ciList)
    {
        this.ciList = ciList;
    }

    public CIDTO getSelectedCI()
    {
        return selectedCI;
    }

    public void setSelectedCI(CIDTO selectedCI)
    {
        this.selectedCI = selectedCI;
    }

    public List<TypeDTO> getTypeList()
    {
        return typeList;
    }

    public void setTypeList(List<TypeDTO> typeList)
    {
        this.typeList = typeList;
    }

    public List<AreaDTO> getAreaList()
    {
        return areaList;
    }

    public void setAreaList(List<AreaDTO> areaList)
    {
        this.areaList = areaList;
    }

    public List<AreaValueDTO> getAreaValueList()
    {
        return areaValueList;
    }

    public void setAreaValueList(List<AreaValueDTO> areaValueList)
    {
        this.areaValueList = areaValueList;
    }

    public ArrayList<Long> getAreaValueSelectList()
    {
        return areaValueSelectList;
    }

    public void setAreaValueSelectList(ArrayList<Long> areaValueSelectList)
    {
        this.areaValueSelectList = areaValueSelectList;
    }



}



Code: Select all


I am new to primefaces, could someone please enlighten me as to what I'm doing wrong??

Thanks in advance, any help would be much appreciated.


marcbaechinger
Posts: 25
Joined: 28 Jan 2011, 15:18

28 Jan 2011, 19:23

hi rcowart

I don't know if i can help you but i managed to do what you want to do in my project. I quickly checked out your code and I think your general approach is ok (at least similar as i did it). I can only give you some hints you can try. I don't know if it really helps:

1. Check the partial response which you retrieve from the server onclick of the 'add'-Button. Does it contain empty fields? (use firebug to observe xhr communication)
2. Try to replace the entire dialog instead of #grid-2 only
3. Create another <h:form> for the dialog only and also replace the form by the partial request

hope that helps a little
good luck
marc

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 34 guests