2

这个项目是用 Primefaces 3.5、JSF 2.0、Oracle 数据库制作的。

风景:

<h:form id="schedule" class="schedule">

// more JSF and forms and dialogs

<p:dialog widgetVar="patientDialog" dynamic="true" header="Find Patient" showEffect="clip" hideEffect="explode" modal="true" >
            <h:form id="frmPatient">
                <h:panelGrid id="findPatient" columns="1">
                    <h:panelGrid id="findPatientParameters" columns="2">
                        <h:outputLabel value="Firstname: " /> 
                        <p:inputText id="name" label="name" size="15" value="#{waitinglistBean.name}" />
                        <h:outputLabel value="Patient Code: " /> 
                        <p:inputText id="pcode" label="pcode" size="15" value="#{waitinglistBean.pcode}" />
                        <br />
                        <p:commandButton value="Search" process="name" actionListener="#{waitinglistBean.patients}" update="patients"/>
                    </h:panelGrid>
                    <h:panelGrid id="findPatientDetails" columns="1">
                        <p:dataTable id="patients" var="patient" resizableColumns="true" scrollable="true" scrollWidth="1250" 
                                     scrollHeight="150" value="#{waitinglistBean.patients}" 
                                     rowKey="#{patient.PCode}" selection="#{waitinglistBean.selectedPatient}" 
                                     selectionMode="single" >
                            <f:facet name="header">  
                                Click "Select" button after selecting a row to select patient.
                            </f:facet>  
                            <p:column width="150" headerText="Code">  
                                #{patient.PCode}  
                            </p:column>  
                            <p:column width="150" headerText="Family Name">  
                                #{patient.PLname}  
                            </p:column>  
                            <p:column width="150" headerText="First Name">  
                                #{patient.PFname}  
                            </p:column> 
                            <p:column headerText="Sex" >  
                                #{patient.PSex}  
                            </p:column>  
                            <p:column headerText="Birthdate">  
                                #{patient.PBorn}  
                            </p:column> 
                            <p:column headerText="Street">  
                                #{patient.PStreet}  
                            </p:column>
                            <f:facet name="footer">  
                                <p:commandButton id="viewButton" value="Select" icon="ui-icon-search"  
                                        oncomplete="patientDialog.hide()" 
                                        update=":frmDialogs:frmWaiting:tabView:patientDetails" 
                                        process="patients"/>  
                            </f:facet>
                        </p:dataTable>
                    </h:panelGrid>
                </h:panelGrid>
            </h:form>
        </p:dialog>
    <p:dialog widgetVar="patientDialog" dynamic="true" header="Find Patient" showEffect="clip" hideEffect="explode" modal="true" >
            <h:form id="frmPatient">
                <h:panelGrid id="findPatient" columns="1">
                    <h:panelGrid id="findPatientParameters" columns="2">
                        <h:outputLabel value="Firstname: " /> 
                        <p:inputText id="name" label="name" size="15" value="#{waitinglistBean.name}" />
                        <h:outputLabel value="Patient Code: " /> 
                        <p:inputText id="pcode" label="pcode" size="15" value="#{waitinglistBean.pcode}" />
                        <br />
                        <p:commandButton value="Search" process="name" actionListener="#{waitinglistBean.patients}" update="patients"/>
                    </h:panelGrid>
                    <h:panelGrid id="findPatientDetails" columns="1">
                        <p:dataTable id="patients" var="patient" resizableColumns="true" scrollable="true" scrollWidth="1250" 
                                     scrollHeight="150" value="#{waitinglistBean.patients}" 
                                     rowKey="#{patient.PCode}" selection="#{waitinglistBean.selectedPatient}" 
                                     selectionMode="single" >
                            <f:facet name="header">  
                                Click "Select" button after selecting a row to select patient.
                            </f:facet>  
                            <p:column width="150" headerText="Code">  
                                #{patient.PCode}  
                            </p:column>  
                            <p:column width="150" headerText="Family Name">  
                                #{patient.PLname}  
                            </p:column>  
                            <p:column width="150" headerText="First Name">  
                                #{patient.PFname}  
                            </p:column> 
                            <p:column headerText="Sex" >  
                                #{patient.PSex}  
                            </p:column>  
                            <p:column headerText="Birthdate">  
                                #{patient.PBorn}  
                            </p:column> 
                            <p:column headerText="Street">  
                                #{patient.PStreet}  
                            </p:column>
                            <f:facet name="footer">  
                                <p:commandButton id="viewButton" value="Select" icon="ui-icon-search"  
                                        oncomplete="patientDialog.hide()" 
                                        update=":frmDialogs:frmWaiting:tabView:patientDetails" 
                                        process="patients"/>  
                            </f:facet>
                        </p:dataTable>
                    </h:panelGrid>
                </h:panelGrid>
            </h:form>
        </p:dialog>
    // more JSF and dialogshizzle
 </h:form>

支持bean:

@ManagedBean(name="waitinglistBean")
@ViewScoped
public class WaitinglistBean implements Serializable
{
private Patients patient;
private OrWaitinglist orWaitinglist;
private List<Patients> patients = new ArrayList<Patients>();
private String name;
private Integer pcode;

public WaitinglistBean() {

}

public void setSelectedPatient(Patients patient) {
    this.patient = patient;
}
public Patients getSelectedPatient() {
    return patient;
}
public OrWaitinglist getOrWaitinglist() {
    return orWaitinglist;
}
public void setOrWaitinglist(OrWaitinglist orWaitinglist) {
    this.orWaitinglist = orWaitinglist;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public Integer getPcode() {
    return pcode;
}
public void setPcode(Integer pcode) {
    this.pcode = pcode;
}

public List<Patients> getPatients() {
    PatientsDao patientsDao = new PatientsDaoImpl();
    patients = patientsDao.getSearchPatient(name, pcode);
    System.out.println(name + " " + pcode);
    return patients;
}

public void createOrWaitinglist()
{
    orWaitinglist.setPatients(patient);
}

因此,首先用户输入一个字符串:“Firstname”和一个整数:“Patient Code”。当他点击“搜索”按钮时,它会触发该命令按钮内的 actionListener="#{patientBean.patients}。该方法需要 2 个参数,名称和 pcode,它们有自己的 setter/getter。

当我在控制台中查看时,它显示了这两个参数的打印输出,它们是两次“null”,这意味着来自 JSF 页面的参数没有传递给支持 bean,尽管 inputText 的值已设置为backingbean 设置方法:value="#{patientBean.name}"

我现在的问题是为什么我会得到这些空值。我已经阅读了几篇使用这些设置器的帖子,但我仍然得到空值。

编辑后我仍然有同样的问题;

4

1 回答 1

2

对于将输入组件的值发送h:panelgrid到 backingbean,请使用以下内容:

<p:commandButton value="Search" process="@(frmPatient:findPatientParameters :input)" 
           actionListener="#{patientBean.patients}" update="patients"/>
于 2013-04-11T19:18:53.500 回答