支持bean方法从输入中获取null [英] Backing bean method is getting null from inputs

查看:36
本文介绍了支持bean方法从输入中获取null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该项目由Primefaces 3.5,JSF 2.0,Oracle数据库组成.

This project is made with Primefaces 3.5, JSF 2.0, Oracle database.

视图:

<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>

后备豆:

@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} 在该命令按钮中.该方法需要两个参数,即名称和pcode,它们具有自己的设置器/获取器.

So first a user enter a string: "Firstname" and an Integer: "Patient Code". When he hits the "Search" button it fires the actionListener="#{patientBean.patients} inside that commandbutton. The method needs 2 parameter, name and pcode which have their own setters/getters.

当我在控制台中查看时,它向我显示了这两个参数的打印输出,并且它们两次都是"null",因此,尽管inputText的值具有设置为backingbean设置方法:value =#{PatientBean.name}"

When I look in console it shows me the printout of these 2 parameters, and they are twice "null", so that means the parameters from the JSF pages were not passed to the backing bean, although the value of the inputText has been set to the backingbean set method: value="#{patientBean.name}"

我现在的问题是为什么我要得到这些空值.我已经阅读了几篇使用这些setter的文章,但仍然得到空值.

My question now is why do I get these null-values. I've read several posts which use these setters, but still I get null-values.

编辑后,我仍然遇到相同的问题;

after edit i still have the same problem;

推荐答案

用于将h:panelgrid中的输入组件的值发送到backingbean使用类似这样的东西:

for send value of input component in h:panelgrid to the backingbean use somthing like this:

<p:commandButton value="Search" process="@(frmPatient:findPatientParameters :input)" 
           actionListener="#{patientBean.patients}" update="patients"/>

这篇关于支持bean方法从输入中获取null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆