命令按钮充电空值

command button charge empty values

我正在使用 jsf2.2 primefaces 6.0,我创建了可点击的界面,显示了点击 table.After 的需求的详细信息,我创建了一个命令按钮,在 2 个特定条件下显示(仅当需求是 "Encours" 或 "Amodifier" 时)。我的问题是当我尝试加载需求详细信息时抛出 "modifier" 按钮它收取空 values.It 仅当我先行时加载完整值单击 table 之前显示需求详细信息。 我需要帮助来解决这个问题,因为之后我需要 "modifier" 按钮来更新数据。

xhtml 页面:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui" xmlns:jsf="http://xmlns.jcp.org/jsf"
    xmlns:pt="http://xmlns.jcp.org/jsf/passthrought"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    template="/facelets/template.xhtml">
    <ui:define name="pageTitle">espace employer</ui:define>
    <ui:define name="content">
        <ul class="breadcrumb">
            <li><i class="ace-icon fa fa-home home-icon"></i> <a
                href="employerHome.jsf">Acceuil</a></li>
            <li class="active">espace Employé</li>
        </ul>
        <!-- /.breadcrumb -->

    </ui:define>
    <ui:define name="pageHeader">
        <h1></h1>

    </ui:define>
    <ui:define name="pageContent">
        <h:form id="form">
            <p:panel header="Mes Demandes">

                <p:dataTable id="tt1" selectionMode="single" rowKey="#{d.id}"
                    value="#{demandeBean.allDemandesParEmployer}" var="d"
                    emptyMessage="Aucune demande">

                    <p:ajax event="rowSelect" listener="#{demandeBean.onRowSelect}"
                        oncomplete="PF('d3').show()" update=":form:d3" />
                    <p:column headerText="Date">
                        <h:outputText value="#{d.dateDeDepot}">
                            <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"
                                timeZone="GMT+1:00" />
                        </h:outputText>
                    </p:column>

                    <p:column headerText="État">
                        <h:outputText value="#{d.etatDemande}" />
                    </p:column>
                    <p:column style="text-align: center" headerText="Visualiser">
                        <p:commandButton update="@form" oncomplete="PF('diag').show()"
                            icon="ui-icon-search" title="View">
                            <f:setPropertyActionListener value="#{d}"
                                target="#{demandeBean.demandeSelectionnee}" />
                        </p:commandButton>
                    </p:column>
                    <p:column headerText="Action">
                        <p:commandButton value="Modifier" icon="ui-icon-disk" onclick="PF('d3').show();"
                            rendered="#{d.etatDemande == 'ENCOURS'|| d.etatDemande == 'AMODIFIER'}">
                        <f:setPropertyActionListener value="#{d}"
                                target="#{demandeBean.demandeSelectionnee}" />
                        </p:commandButton>
                    </p:column>

                </p:dataTable>

            </p:panel>
            <p:panel rendered="#{not empty demandeBean.allDemandesParAssures}"
                header="Mes assurés demandes">
                <p:dataTable value="#{demandeBean.allDemandesParAssures}" var="d"
                    selectionMode="single" rowKey="#{d.id}"
                    emptyMessage="Aucune demande">
                    <p:ajax event="rowSelect" listener="#{demandeBean.onRowSelect}"
                        oncomplete="PF('d2').show()" update=":form:d2" />
                    <p:column headerText="État">
                        <h:outputText value="#{d.dateDeDepot}">
                            <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"
                                timeZone="GMT+1:00" />
                        </h:outputText>
                    </p:column>

                    <p:column headerText="Assuré">
                        <h:outputText value="#{d.employer.name} #{d.employer.prenom}" />
                    </p:column>
                    <p:column headerText="État">
                        <h:outputText value="#{d.etatDemande}" />
                    </p:column>

                    <p:column style="text-align: center" headerText="Visualiser">
                        <p:commandButton update="@form" oncomplete="PF('diag').show()"
                            icon="ui-icon-search" title="View">
                            <f:setPropertyActionListener value="#{d}"
                                target="#{demandeBean.demandeSelectionnee}" />
                        </p:commandButton>
                    </p:column>
                </p:dataTable>

            </p:panel>



            <p:dialog header="Détails demande" widgetVar="d2" modal="true"
                id="d2" dynamic="true" showEffect="fade" hideEffect="fade"
                resizable="true" position="center">
                <p:outputPanel id="p2" style="text-align:center;">
                    <p:dataTable
                        value="#{demandeBean.demandeSelectionnee.detailDemandes}" var="d">
                        <p:column headerText="Acte">
                            <h:outputText value="#{d.acteMedical.typeActe}" />
                        </p:column>
                        <p:column headerText="Montant">
                            <h:outputText value="#{d.montant}" />
                        </p:column>
                        <p:column headerText="Date">
                            <h:outputText value="#{d.dateActe}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                        </p:column>
                        <p:column style="text-align: center" headerText="images"
                            width="10%">
                            <p:commandButton update="@form" oncomplete="PF('diag').show()"
                                rendered="#{not empty a.images}" icon="ui-icon-search"
                                title="View">
                                <f:setPropertyActionListener value="#{a}"
                                    target="#{demandeBean.demandeSelectionnee}" />
                            </p:commandButton>

                        </p:column>
                    </p:dataTable>
                </p:outputPanel>
            </p:dialog>


            <p:dialog header="Détails demande" widgetVar="d3" modal="true"
                id="d3" dynamic="true" showEffect="fade" hideEffect="fade"
                resizable="true" position="center">
                <p:outputPanel id="p3" style="text-align:center;">
                    <p:dataTable
                        value="#{demandeBean.demandeSelectionnee.detailDemandes}" var="d">
                        <p:column headerText="Acte">
                            <h:outputText value="#{d.acteMedical.typeActe}" />
                        </p:column>
                        <p:column headerText="Montant">
                            <h:outputText value="#{d.montant}" />
                        </p:column>
                        <p:column headerText="Date">
                            <h:outputText value="#{d.dateActe}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                        </p:column>
                        <p:column style="text-align: center" headerText="images"
                            width="10%">
                            <p:commandButton update="@form" oncomplete="PF('diag').show()"
                                rendered="#{not empty a.images}" icon="ui-icon-search"
                                title="View">
                                <f:setPropertyActionListener value="#{a}"
                                    target="#{demandeBean.demandeSelectionnee}" />
                            </p:commandButton>

                        </p:column>
                    </p:dataTable>
                </p:outputPanel>
            </p:dialog>

            <p:dialog header="Détails demande" widgetVar="d4" modal="true"
                id="d4" dynamic="true" showEffect="fade" hideEffect="fade"
                resizable="true" position="center">
                <p:outputPanel id="p4" style="text-align:center;">
                    <p:dataTable
                        value="#{demandeBean.demandeSelectionnee.detailDemandes}" var="d">
                        <p:column headerText="Acte">
                            <h:outputText value="#{d.acteMedical.typeActe}" />
                        </p:column>
                    </p:dataTable>
                </p:outputPanel>
            </p:dialog>






            <p:dialog header="images" widgetVar="diag" modal="true"
                showEffect="fade" hideEffect="fade" resizable="true"
                position="center" height="500" width="650">
                <p:outputPanel id="gal" style="text-align:center;">
                    <p:galleria value="#{demandeBean.demandeSelectionnee.images}"
                        showFilmstrip="true" autoPlay="false" var="image">
                        <p:graphicImage
                            value="http://localhost:18080/openCars/images/#{image}"
                            alt="Image Description for #{image}" title="#{image}" />
                    </p:galleria>
                </p:outputPanel>
            </p:dialog>

        </h:form>
    </ui:define>
</ui:composition>

java豆子:

package mBeans;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.CellEditEvent;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;

import persistence.ActeMedical;
import persistence.Assure;
import persistence.Demande;
import persistence.DetailDemande;
import persistence.EtatDemande;
import persistence.User;
import services.DemandeServicesLocal;
import services.UserServicesLocal;

@ManagedBean
@ViewScoped
public class DemandeBean {
    private List<String> images = new ArrayList<>();
    private String matriculeForAdminToAdd;
    private List<DetailDemande> detailDemandesTMP = new ArrayList<>();
    private ActeMedical acteMedical = new ActeMedical();
    private List<ActeMedical> acteMedicalsToAdd = new ArrayList<>();
    private Integer idOf;
    private List<Demande> allDemandes = new ArrayList<>();
    private List<Demande> allDemandesParAssures = new ArrayList<>();
    private List<Demande> allDemandesParEmployer = new ArrayList<>();
    private Demande demande = new Demande();
    private Demande demandeSelectionnee = new Demande();
    private List<String> etats = new ArrayList<>();
    private String etatChoisi = "";
    private Date dateActe;
    private Double montant;
    private ActeMedical acteMedicalSelection = new ActeMedical();
    private List<ActeMedical> acteMedicals = new ArrayList<>();
    private List<Assure> assuresParEmployee = new ArrayList<>();
    @EJB
    private DemandeServicesLocal demandeServicesLocal;
    @EJB
    private UserServicesLocal userServicesLocal;
    @ManagedProperty(value = "#{identity}")
    private Identity identity;

    @PostConstruct
    public void init() {
        etats.add("ENCOURS");
        etats.add("ACCEPTE");
        etats.add("AMODIFIER");
    }

    public List<String> completeTheme(String query) {
        List<User> users = userServicesLocal.findAllUsers();
        List<String> list = new ArrayList<>();
        for (User u : users) {
            list.add(u.getMatricule());
        }

        return list;
    }

    public void addDetailToList() {
        DetailDemande detailDemande = new DetailDemande(dateActe, demande, acteMedical, montant);
        detailDemandesTMP.add(detailDemande);

        detailDemande = new DetailDemande();
        vider();

    }

    public void deleteDetailToList(DetailDemande detailDemande) {
        detailDemandesTMP.remove(detailDemande);

        detailDemande = new DetailDemande();
        vider();

    }

    public String doAddDemande() {
        demande.setImages(images);
        demande.setEmployer(demandeServicesLocal.findUserById(idOf));
        if (!detailDemandesTMP.isEmpty()) {
            Demande d = demandeServicesLocal.addDemande(demande);
            for (DetailDemande t : detailDemandesTMP) {
                demandeServicesLocal.ajouterDetailDemande(t.getDateActe(), d, t.getActeMedical(), t.getMontant());
            }
            demande = new Demande();
            dateActe = null;
            montant = null;
            detailDemandesTMP = new ArrayList<>();

            return "/pages/listDemandesByEmployer?faces-redirect=true";

        } else {

            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Veuillez ajouter un acte médical", "");
            FacesContext.getCurrentInstance().addMessage(null, msg);
            return "";
        }

    }

    public String doAddDemandeBtAdmin() {
        demande.setImages(images);
        demande.setEmployer(demandeServicesLocal.findUserByMatricule(matriculeForAdminToAdd));
        if (!detailDemandesTMP.isEmpty()) {
            Demande d = demandeServicesLocal.addDemande(demande);
            for (DetailDemande t : detailDemandesTMP) {
                demandeServicesLocal.ajouterDetailDemande(t.getDateActe(), d, t.getActeMedical(), t.getMontant());
            }
            demande = new Demande();
            dateActe = null;
            montant = null;
            detailDemandesTMP = new ArrayList<>();

            matriculeForAdminToAdd = null;

            return "/pages/listDemandes?faces-redirect=true";

        } else {

            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Veuillez ajouter un acte médical", "");
            FacesContext.getCurrentInstance().addMessage(null, msg);
            return "";
        }

    }

    public void doSome() {
        System.out.println(idOf);
    }

    public void vider() {
        dateActe = null;
        montant = 0D;
    }

    public void doCreateDetail() {
        demandeServicesLocal.ajouterDetailDemande(dateActe, demande, acteMedicalSelection, montant);

    }

    public List<Demande> getAllDemandes() {
        allDemandes = demandeServicesLocal.findAllDemandes();
        return allDemandes;
    }

    public void traiterDemande() {
        if (etatChoisi.equals("ACCEPTE")) {

            demandeServicesLocal.addDemande(demandeSelectionnee);
        } else if (etatChoisi.equals("AMODIFIER")) {
            demandeSelectionnee.setEtatDemande(EtatDemande.AMODIFIER);
            demandeServicesLocal.addDemande(demandeSelectionnee);
        }
    }

    public int hatImagesSize() {
        System.out.println(images.size());
        return images.size();
    }

    public void setAllDemandes(List<Demande> allDemandes) {
        this.allDemandes = allDemandes;
    }

    public Demande getDemande() {
        return demande;
    }

    public void setDemande(Demande demande) {
        this.demande = demande;
    }

    public List<Demande> getAllDemandesParEmployer() {
        allDemandesParEmployer = demandeServicesLocal.findAllDemandesParEmployer(identity.getUser());
        return allDemandesParEmployer;
    }

    public void setAllDemandesParEmployer(List<Demande> allDemandesParEmployer) {
        this.allDemandesParEmployer = allDemandesParEmployer;
    }

    public DemandeServicesLocal getDemandeServicesLocal() {
        return demandeServicesLocal;
    }

    public void setDemandeServicesLocal(DemandeServicesLocal demandeServicesLocal) {
        this.demandeServicesLocal = demandeServicesLocal;
    }

    public Identity getIdentity() {
        return identity;
    }

    public void setIdentity(Identity identity) {
        this.identity = identity;
    }

    public void onRowSelect(SelectEvent event) {
        demandeSelectionnee = (Demande) event.getObject();
        FacesMessage msg = new FacesMessage("Car Selected", ((Demande) event.getObject()).getEtatDemande().toString());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    public void onRowUnselect(UnselectEvent event) {
        FacesMessage msg = new FacesMessage("Car Unselected",
                ((Demande) event.getObject()).getEtatDemande().toString());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    public Demande getDemandeSelectionnee() {
        return demandeSelectionnee;
    }

    public void setDemandeSelectionnee(Demande demandeSelectionnee) {
        this.demandeSelectionnee = demandeSelectionnee;
    }

    public List<String> getEtats() {
        return etats;
    }

    public void setEtats(List<String> etats) {
        this.etats = etats;
    }

    public String getEtatChoisi() {
        return etatChoisi;
    }

    public void setEtatChoisi(String etatChoisi) {
        this.etatChoisi = etatChoisi;
    }

    public Date getDateActe() {
        dateActe = new Date();
        return dateActe;
    }

    public void setDateActe(Date dateActe) {
        this.dateActe = dateActe;
    }

    public Double getMontant() {
        return montant;
    }

    public void setMontant(Double montant) {
        this.montant = montant;
    }

    public ActeMedical getActeMedicalSelection() {
        return acteMedicalSelection;
    }

    public void setActeMedicalSelection(ActeMedical acteMedicalSelection) {
        this.acteMedicalSelection = acteMedicalSelection;
    }

    public List<ActeMedical> getActeMedicals() {
        acteMedicals = demandeServicesLocal.findAllActe();
        return acteMedicals;
    }

    public void setActeMedicals(List<ActeMedical> acteMedicals) {
        this.acteMedicals = acteMedicals;
    }

    public List<Assure> getAssuresParEmployee() {
        assuresParEmployee = demandeServicesLocal.findAssuresByEmployee(identity.getUser());
        return assuresParEmployee;
    }

    public void setAssuresParEmployee(List<Assure> assuresParEmployee) {
        this.assuresParEmployee = assuresParEmployee;
    }

    public Integer getIdOf() {
        return idOf;
    }

    public void setIdOf(Integer idOf) {
        this.idOf = idOf;
    }

    public List<Demande> getAllDemandesParAssures() {
        allDemandesParAssures = demandeServicesLocal.findAllDemandesParAssureDeEmployer(identity.getUser());
        return allDemandesParAssures;
    }

    public void setAllDemandesParAssures(List<Demande> allDemandesParAssures) {
        this.allDemandesParAssures = allDemandesParAssures;
    }

    public ActeMedical getActeMedical() {
        return acteMedical;
    }

    public void setActeMedical(ActeMedical acteMedical) {
        this.acteMedical = acteMedical;
    }

    public List<ActeMedical> getActeMedicalsToAdd() {
        return acteMedicalsToAdd;
    }

    public void setActeMedicalsToAdd(List<ActeMedical> acteMedicalsToAdd) {
        this.acteMedicalsToAdd = acteMedicalsToAdd;
    }

    public List<DetailDemande> getDetailDemandesTMP() {
        return detailDemandesTMP;
    }

    public void setDetailDemandesTMP(List<DetailDemande> detailDemandesTMP) {
        this.detailDemandesTMP = detailDemandesTMP;
    }

    public String getMatriculeForAdminToAdd() {
        return matriculeForAdminToAdd;
    }

    public void setMatriculeForAdminToAdd(String matriculeForAdminToAdd) {
        this.matriculeForAdminToAdd = matriculeForAdminToAdd;
    }

    public List<String> getImages() {
        return images;
    }

    public void setImages(List<String> images) {
        this.images = images;
    }

    public void onCellEdit(CellEditEvent event) {
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        demandeSelectionnee = demandeServicesLocal.findDemandeById(Integer.valueOf(event.getRowKey()));
        if (newValue != null && !newValue.equals(oldValue)) {
            if (newValue.equals("ENCOURS")) {
                demandeSelectionnee.setEtatDemande(EtatDemande.ENCOURS);
                demandeServicesLocal.addDemande(demandeSelectionnee);
            } else if (newValue.equals("AMODIFIER")) {
                demandeSelectionnee.setEtatDemande(EtatDemande.AMODIFIER);
                demandeServicesLocal.addDemande(demandeSelectionnee);
            } else if (newValue.equals("ACCEPTE")) {
                demandeSelectionnee.setEtatDemande(EtatDemande.TRANSMISE);
                demandeServicesLocal.addDemande(demandeSelectionnee);
            }

            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed",
                    "Old: " + oldValue + ", New:" + newValue);
            FacesContext.getCurrentInstance().addMessage(null, msg);

        }
    }

}

如果我没理解错你的问题,首先我认为你的按钮必须有 oncomplete="PF('d3').show();" 而不是 onclick="PF('d3').show();" 并且它必须具有 update="d3" 属性,其中 d3 是正确的对话框小部件 ID。 让我们解释一下它是如何工作的:首先单击按钮 - 它会更新 javaBean 中的 属性,然后它将使用来自后端的新更改更新对话框。最后,请求结束后,它会打开对话框。