1

我创建了一个 CRUD 页面,它可以添加、删除、更新数据库中的表。但是,我对p:commandButton. actionListener没有触发,我在控制台中看不到任何错误。

cpret.xhtml

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">



<h:head><title>Chargé clientele</title>
</h:head>

<h:body>
<ui:composition template="/layout.xhtml">
<ui:define name="menu">
<h:form id="menu">
<p:outputPanel id="panel" autoUpdate="true" >
<h:panelGrid columns="1" style="align:center;">
<p:commandButton value="Ajouter Pret" action="#{chargepretBean.add}" style="width:250px;" update=":add" oncomplete="addWid.show()"></p:commandButton>
<p:commandButton value="Modifier Pret" disabled="#{chargepretBean.selectedValue ==null}" style="width:250px;" update=":add" action="#{chargepretBean.edit}" oncomplete="addWid.show()"></p:commandButton>
<p:commandButton value="Supprimer Pret" disabled="#{chargepretBean.selectedValue ==null}"  onclick="deleteEl.show()" style="width:250px;" type="button"></p:commandButton>

</h:panelGrid>
</p:outputPanel>
<p:confirmDialog widgetVar="deleteEl" message="Voulez vous réellement supprimer l'élément?" severity="alert">
<p:commandButton value="Annuler" type="button" onclick="deleteEl.hide()"></p:commandButton>
<p:commandButton value="Valider" action="#{chargepretBean.delete}" oncomplete="deleteEl.hide()" update=":idForm:data"></p:commandButton>
</p:confirmDialog>
</h:form>
</ui:define>

<ui:define name="table">
<h:form id="idForm">
<p:dataTable id="data" value="#{chargepretBean.listData}" var="b" rowKey="#{b.idPret}"
selectionMode="single" selection="#{chargepretBean.selectedValue}" paginator="true" paginatorPosition="bottom" rows="5">
<p:ajax event="rowSelect" update=":menu:panel"/>
<f:facet name="header">  
            Liste des prets  
        </f:facet>  
<p:column headerText="Date de demande"> <h:outputText value="#{b.dateDemande}" /></p:column>
<p:column headerText="Montant"> <h:outputText value="#{b.montant}" /></p:column>
<p:column headerText="nbre de Monsualite"> <h:outputText value="#{b.nbrMonsualite}" /></p:column>
<p:column headerText="Description de pret"> <h:outputText value="#{b.notepret.descriptionp}" /></p:column>
<p:column headerText="Taux d'intéret"> <h:outputText value="#{b.tauxInteret}" /></p:column>
</p:dataTable>
</h:form>


<p:dialog widgetVar="addWid" width="500" height="280">
<f:facet name="header">Ajout/Modification Pret</f:facet>
<h:form id="add">
<p:panelGrid columns="3" style="width:100%;">

<p:outputLabel value="Date de demande :" for="datedemande"></p:outputLabel>
<p:inputMask mask="99/99/9999" id="datedemande" value="#{chargepretBean.pret.dateDemande}" required="true"
requiredMessage="champs obligatoire">
</p:inputMask>
<p:message for="datedemande"></p:message>

<p:outputLabel value="Montant :" for="montant"></p:outputLabel>
<p:inputText id="montant" value="#{chargepretBean.pret.montant}" required="true"
requiredMessage="champs obligatoire">
<f:validateLongRange minimum="0" maximum="3000"></f:validateLongRange>
</p:inputText>
<p:message for="montant"></p:message>

<p:outputLabel value="nbre de Monsualite :" for="nbrMonsualite"></p:outputLabel>
<p:inputText id="nbrMonsualite" value="#{chargepretBean.pret.nbrMonsualite}" required="true"
requiredMessage="champs obligatoire"></p:inputText>
<p:message for="nbrMonsualite"></p:message>

<p:outputLabel value="Description pret :" for="descriptionp"></p:outputLabel>
<p:inputText id="descriptionp" value="#{chargepretBean.notepret.descriptionp}" required="true"
requiredMessage="champs obligatoire"></p:inputText>
<p:message for="descriptionp"></p:message>

<p:outputLabel value="Taux d'interet :" for="tauxInteret"></p:outputLabel>
<p:inputText id="tauxInteret" value="#{chargepretBean.pret.tauxInteret}" required="true"
requiredMessage="champs obligatoire"></p:inputText>
<p:message for="tauxInteret"></p:message>

<f:facet name="footer">  
<p:commandButton value="Enregistrer"  actionListener="#{chargepretBean.save}" update="@form :idForm:data"  process="@form" oncomplete="handleClose(xhr, status, args)"></p:commandButton>
</f:facet>
</p:panelGrid>
</h:form>
</p:dialog>

<script type="text/javascript">
function handleClose(xhr, status, args) { 
if (!args.validationFailed) {
    addWid.hide();
 }
}
</script>
</ui:define>
</ui:composition>
</h:body>

</html>

ChargepretBean.java

package com.isamm.Bean;


import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.event.ActionEvent;


import org.springframework.context.annotation.Scope;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Component;

import com.isamm.Model.Chargepret;
import com.isamm.Model.Notepret;
import com.isamm.Model.Pret;
import com.isamm.Services.ChargepretService;
import com.isamm.Services.PretService;

@Component("chargepretBean")
@Scope
@ManagedBean
public class ChargepretBean implements Serializable {

    @Autowired
    private transient ChargepretService chargepretService;  

    @Autowired
    private transient PretService pretService;

    private List<Chargepret> lstchargeprets;

    private List<Pret> lstprets;

    private boolean fEdit=false;
    private Integer idCharge;

    private List<Pret> listData;

    private Pret selectedValue;

    private Pret pret=new Pret();
    private Notepret notepret = new  Notepret();

    @Autowired()
    private UserBean userBean;

    @PostConstruct
    public void init(){
        idCharge=userBean.getIdUser();
        listData=pretService.consulterPretByChargePret(idCharge);
    }

    public String add(){
        System.out.println("addBean");
        pret=new Pret();
        fEdit=false;
        return null;
    }

    public List<Chargepret> getLstchargeprets() {
        lstchargeprets=chargepretService.findbyall_Chargepret();
        System.out.println(lstchargeprets);
        return lstchargeprets;
    }


    public Boolean edit(){
        System.out.println("editebean");
        this.pret=pretService.finById_Pret(selectedValue.getIdPret());
        System.out.println(selectedValue.getIdPret());
        fEdit=true;
        //pretService.updatePret(pret);
        return fEdit;
    }

    public String delete(){
        System.out.println("deletebean");
        Pret cha=pretService.finById_Pret(selectedValue.getIdPret());
        pretService.deletePret(cha);
        this.selectedValue=null;
        listData=pretService.consulterPretByChargePret(idCharge);
        return null;
    }

    public void save(ActionEvent actionEvent){
        System.out.println("savebean");
        System.out.print("save0");
        Chargepret charge=chargepretService.finById_Chargepret(idCharge);
        pret.setChargepret(charge);

        if(!fEdit){
            System.out.print("save1");
            pretService.savePret(pret);
            System.out.print("save2");
        }else{
            System.out.print("save3");
            pretService.updatePret(pret);
            System.out.print("save4");
        }
        listData=pretService.consulterPretByChargePret(idCharge);
    }

    //getters & setters


    public List<Pret> getLstprets() {
        lstprets = pretService.findbyall_Pret(); 
        return lstprets;
    }

}
4

0 回答 0