1

我正在使用prime faces 3.4.2,并且正在尝试使用行编辑数据表更新包含另一个对象列表的实体。我的问题是,当我验证更改时,实体的简单属性在数据库中更新,但列表没有。我不知道如何将整个对象保存在数据库中。

在这里你可以找到编辑页面:

`

<p:panel style="width:1000px;  ;font: lighter 70.5% Arial, Helvetica, sans-serif ; " header="Informations Générales">
        <p:growl id="growl" showDetail="true" sticky="true" style="font-size: small;"  />  
            <h:panelGrid columns="2" cellpadding="5">
                <h:outputLabel value="Société" />
                <p:inputText id="custSoc" value="#{CustomerCtrl.selectedCust.company}"/>

                <h:outputLabel value="Secteur d'activité" />
                <p:inputText id="custActivite" value="#{CustomerCtrl.selectedCust.secteurActivite}"  />

                <h:outputLabel value="Nom du propriétaire" />
                <p:inputText id="custprop" value="#{CustomerCtrl.selectedCust.proprietaire}"  />
           </h:panelGrid>

        <p:tabView id="tabView">    
            <p:tab title="Coordonnées">

<p:growl id="messages" showDetail="true"/>  

<p:dataTable var="cu" value="#{CustomerCtrl.selectedCust.coordonnee}" id="carList" editable="true">  

    <f:facet name="header">  
       Coordonnées  
    </f:facet>  

        <p:columnGroup type="header">  
        <p:row>  
            <p:column colspan="5" headerText="Adresses"  />                    
            <p:column colspan="5" headerText="Contacts" />  

        </p:row>  

        <p:row>  
            <p:column headerText="Num" style="width:2cm"/>  
            <p:column headerText="Rue/Avenue" style="width:3cm"/>  
            <p:column headerText="Code postal" style="width:2cm" />                   
            <p:column headerText="Ville" style="width:2.5cm" /> 
            <p:column headerText="Pays" style="width:2.5cm" />
            <p:column headerText="Fixe" style="width:2cm"/>
            <p:column headerText="Mobile" style="width:2cm"/>
            <p:column headerText="Fax" style="width:2cm"/>
            <p:column headerText="E-mail" style="width:3.7cm"/>
            <p:column headerText=" " />

        </p:row>
        </p:columnGroup>

    <p:ajax event="rowEdit" listener="#{CustomerCtrl.onEdit}" update=":form:messages" />  
    <p:ajax event="rowEditCancel" listener="#{CustomerCtrl.onCancel}" update=":form:messages" />  

    <p:column headerText="Num">  
        <p:cellEditor>  
            <f:facet name="output">  
                <h:outputText value="#{cu.number}" />  
            </f:facet>  
            <f:facet name="input">  
                <p:inputText value="#{cu.number}" style="width:90%"/>  
            </f:facet>  
        </p:cellEditor>  
    </p:column> 

    <p:column headerText="Rue/Avenue">  
        <p:cellEditor>  
            <f:facet name="output">  
                <h:outputText value="#{cu.street}" />  
            </f:facet>  
            <f:facet name="input">  
                <p:inputText value="#{cu.street}" style="width:90%"/>  
            </f:facet>  
        </p:cellEditor>  
    </p:column>  

    <p:column headerText="Code postal">  
        <p:cellEditor>  
            <f:facet name="output">  
                <h:outputText value="#{cu.zipcode}" />  
            </f:facet>  
            <f:facet name="input">  
                <p:inputText value="#{cu.zipcode}" style="width:90%"/>  
            </f:facet>  
        </p:cellEditor>  
    </p:column> 

     <p:column headerText="Ville">  
        <p:cellEditor>  
            <f:facet name="output">  
                <h:outputText value="#{cu.city.text}" />  
            </f:facet>  
            <f:facet name="input">  
                <h:selectOneMenu value="#{cu.city.text}" style="width:100%">  
                    <f:selectItems value="#{CustomerCtrl.cityList}" style="width:100%" 
                        var="city"   
                        itemLabel="#{city}"  
                        itemValue="#{city}" />  
                </h:selectOneMenu>  
            </f:facet>  
        </p:cellEditor>  
    </p:column>  

     <p:column headerText="Pays" >  
        <p:cellEditor>  
            <f:facet name="output">  
                <h:outputText value="#{cu.country.text}" style="width:100%" />  
            </f:facet>  
            <f:facet name="input">  
                <h:selectOneMenu value="#{cu.country.text}" style="width:100%">  
                    <f:selectItems value="#{CustomerCtrl.countryList}"  style="width:100%"
                        var="color"   
                        itemLabel="#{color}"  
                        itemValue="#{color}" />  
                </h:selectOneMenu>  
            </f:facet>  
        </p:cellEditor>  
    </p:column> 

    <p:column headerText="Fixe">  
        <p:cellEditor>  
            <f:facet name="output">  
                <h:outputText value="#{cu.phone}" />  
            </f:facet>  
            <f:facet name="input">  
                <p:inputText value="#{cu.phone}" style="width:90%"/>  
            </f:facet>  
        </p:cellEditor>  
    </p:column>

    <p:column headerText="Mobile" >  
        <p:cellEditor>  
            <f:facet name="output">  
                <h:outputText value="#{cu.mobile}" />  
            </f:facet>  
            <f:facet name="input">  
                <p:inputText value="#{cu.mobile}" style="width:90%"/>  
            </f:facet>  
        </p:cellEditor>  
    </p:column>

    <p:column headerText="Fax" >  
        <p:cellEditor>  
            <f:facet name="output">  
                <h:outputText value="#{cu.fax}" />  
            </f:facet>  
            <f:facet name="input">  
                <p:inputText value="#{cu.fax}" style="width:90%"/>  
            </f:facet>  
        </p:cellEditor>  
    </p:column>

    <p:column headerText="E-mail" >  
        <p:cellEditor>  
            <f:facet name="output">  
                <h:outputText value="#{cu.email}" />  
            </f:facet>  
            <f:facet name="input">  
                <p:inputText value="#{cu.email}" style="width:90%"/>  
            </f:facet>  
        </p:cellEditor>  
    </p:column>

    <p:column style="width:6%">  
        <p:rowEditor />  
    </p:column>  

</p:dataTable>


           </p:tab>
           <p:tab title="Compte">
                <h:panelGrid columns="2" cellpadding="5">
                <h:outputLabel value="Login"  />
                <p:inputText id="userLogin" value="#{CustomerCtrl.selectedCust.login}"  />

                <h:outputLabel value="Mot de passe"  />
                <p:password id="userpass" value="#{CustomerCtrl.selectedCust.password}"  />
                </h:panelGrid>
            </p:tab>
              <p:tab title="Applications">
                <h:panelGrid columns="2" cellpadding="5">


                </h:panelGrid>
            </p:tab>
              <p:tab title="Interventions">
                <h:panelGrid columns="2" cellpadding="5">   
                </h:panelGrid>
            </p:tab>

            </p:tabView>    
        </p:panel>
      <br/>

`

这是我的托管豆:`@ManagedBean(name = "CustomerCtrl") @ViewScoped public class CustomerController implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private int idSelected;

private Customer selectedCust ;

private Coordonnee selectedCoord = new Coordonnee();

private Coordonnee filteredCoord = new Coordonnee();

private List<Customer> filteredCusts;

private int cityId;

private int countryId;

private List<SelectItem> cityList = new ArrayList<SelectItem>();

private List<SelectItem> countryList = new ArrayList<SelectItem>();

private List<Customer> custmrs = new ArrayList<Customer>();

private List<Coordonnee> coordonnees = new ArrayList<Coordonnee>();

private Coordonnee selectedCustomerCoordonne;

@EJB
private SettingsBean settingBean;

public CustomerController() {
    if (selectedCust != null) {
        coordonnees = (List<Coordonnee>) settingBean.FindCoordonneeByCustomer(selectedCust.getId());
    }
}

public void createCustomer() {
    System.out.println("hello createCustomer");
    System.out.println("selectedcust :"+selectedCust.getCompany());
    System.out.println("selectedcustCoordonnee 1 :"+selectedCustomerCoordonne);
    if(selectedCust==null){
        System.out.println("entré");
        selectedCust= new Customer();
        System.out.println("nouvelle instance créé");
        settingBean.createCustomer(selectedCust);
        settingBean.createCoordonnee(selectedCustomerCoordonne);
        System.out.println("Nouveau client " + selectedCust.getCompany() + " ajoutée");
    }
    else{
        System.out.println("editer");
        selectedCust.setCoordonnee(coordonnees);
        settingBean.editCustomer(selectedCust);
        System.out.println("client " + selectedCust.getCompany() + " édité");   
    }
}

public List<Customer> getCustmrs() {
    custmrs = settingBean.findAllCustomers();
    return custmrs;
}

public void setCustmrs(List<Customer> custmrs) {
    this.custmrs = custmrs;
}

public void preRenderView() {
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
            .getExternalContext().getSession(true);
}

public Customer getSelectedCust() {
    if (selectedCust == null) {
        selectedCust = (Customer) FacesContext.getCurrentInstance()
                .getExternalContext().getSessionMap().get("selectedCust");
        System.out.println("Par session");
        if (selectedCust == null) {
            selectedCust = new Customer();
            selectedCust.setCoordonnee(new ArrayList<Coordonnee>());
        } else
        selectedCust.setCoordonnee(settingBean
                .FindCoordonneeByCustomer(selectedCust.getId()));

    }
    return selectedCust;
}

public void setSelectedCust(Customer selectedCust) {
    this.selectedCust = selectedCust;
}

public List<Customer> getFilteredCusts() {
    return filteredCusts;
}

public void setFilteredCusts(List<Customer> filteredCusts) {
    this.filteredCusts = filteredCusts;
}

public List<Coordonnee> getCoordonnees() {
    if (selectedCust != null) {
        coordonnees = (List<Coordonnee>) settingBean.FindCoordonneeByCustomer(selectedCust.getId());
    }
    return coordonnees;
}

public void setCoordonnees(List<Coordonnee> coordonnees) {
    this.coordonnees = coordonnees;
}

public void setCustomerToEdit(Customer customerToEdit) {
}

public String removeCustomer() {
    if (selectedCust != null) {
        System.out.println("in delete");
        String selected = selectedCust.getCompany();
        System.out.println("supprimer " + selected + "");
        custmrs.remove(selectedCust);
        settingBean.removeCustomer(selectedCust);
        System.out.println("client supprimé");
    }
    return "";
}


    public String removeCustomercoordonnee() {
    if (selectedCustomerCoordonne != null) {
        System.out.println("coordonne in delete");
        String selected = selectedCustomerCoordonne.getEmail();
        System.out.println("supprimer " + selected + "");
        settingBean.removeCustomerCoordonnee(selectedCustomerCoordonne);
        System.out.println("coordonne supprimé");
    }
    return "";
}

public String editCustomer() {
    if (selectedCust != null) {
        FacesContext.getCurrentInstance().getExternalContext()
                .getSessionMap().put("selectedCust", selectedCust);
        System.out.println("selected "
                + FacesContext.getCurrentInstance().getExternalContext()
                        .getSessionMap().get("selectedCust"));
    }
    return "customeradd.xhtml?faces-redirect=true";

}

public int getCityId() {
    return cityId;
}

public void setCityId(int cityId) {
    this.cityId = cityId;
}

public int getCountryId() {
    return countryId;
}

public void setCountryId(int countryId) {
    this.countryId = countryId;
}

public List<SelectItem> getCityList() {
    cityList = new ArrayList<SelectItem>();
    List<City> Listcity = settingBean.findAllCity();
    for (City c : Listcity) {
        cityList.add(new SelectItem(c.getId(), c.getText()));
    }
    return cityList;
}

public void setCityList(List<SelectItem> cityList) {
    this.cityList = cityList;
}

public List<SelectItem> getCountryList() {
    cityList = new ArrayList<SelectItem>();
    List<Country> Listcountry = settingBean.findAllCountry();
    for (Country c : Listcountry) {
        countryList.add(new SelectItem(c.getId(), c.getText()));
    }
    return countryList;
}

public void setCountryList(List<SelectItem> countryList) {
    this.countryList = countryList;
}

public int getIdSelected() {
    return idSelected;
}

public void setIdSelected(int idSelected) {
    this.idSelected = idSelected;
}

public Coordonnee getSelectedCustomerCoordonne() {

    return selectedCustomerCoordonne;
}

public void setSelectedCustomerCoordonne(
        Coordonnee selectedCustomerCoordonne) {
    this.selectedCustomerCoordonne = selectedCustomerCoordonne;
}

public Coordonnee getSelectedCoord() {
    return selectedCoord;
}

public void setSelectedCoord(Coordonnee selectedCoord) {
    this.selectedCoord = selectedCoord;
}

public Coordonnee getFilteredCoord() {
    return filteredCoord;
}

public void setFilteredCoord(Coordonnee filteredCoord) {
    this.filteredCoord = filteredCoord;
}

public void onEdit(RowEditEvent event) {  
    FacesMessage msg = new FacesMessage("Cliquer sur enregistrer pour valider la modification", ((Coordonnee) event.getObject()).getCustomer().getCompany());  

    FacesContext.getCurrentInstance().addMessage(null, msg);  
}  

public void onCancel(RowEditEvent event) {  
    FacesMessage msg = new FacesMessage("Modification annulée", ((Coordonnee) event.getObject()).getCustomer().getCompany());  

    FacesContext.getCurrentInstance().addMessage(null, msg);  
}  

}`

请帮我保存这两个对象。

4

0 回答 0