【发布时间】:2023-03-07 00:57:01
【问题描述】:
我有一个带有表单的简单 JSF 应用程序,其中一个控件是 selectOneListbox:
<h:selectOneListbox style="width: 231px; height: 27px;position:absolute;left:400px;top:325px;" value="#{PatientsSearch.selectedDoctor}">
<f:selectItems value="#{PatientsSearch.doctors}" var="d" itemLabel="#{d.name}" itemValue="#{d.name}" />
</h:selectOneListbox>
当我运行应用程序时,我可以看到正在填充的列表(即,PatientSearch.doctors 已正确检索),因此我可以从 selectOneListbox 中选择一项。在我选择了所需的项目后,该表单不再起作用。所有其他按钮似乎都处于空闲状态,它们不再对点击做出反应。但是,如果没有从 selectOneListbox 中选择任何内容,则所有按钮都会按预期工作(即它们在托管 bean 中触发它们的回调)。
我调试了应用程序并注意到,在列表中选择一个项目后,表单上其他按钮的回调在单击它们时不会被触发。 同样在调试器中,我从来没有看到 setSelectedDoctor() 像我预期的那样被调用(参见上面的 sn-p)。
我正在使用 JSF 的 Mojarra 2.0.1 实现。
我在这里错过了什么?
更新:这是整个表格:
<h:form style="width: 876px; background-color: #FED981; padding-left: 60px; padding-top: 30px; margin-left: 80px; margin-top: 40px; color: #804000; font-style: normal; font-family: Verdana, Arial, Sans-Serif">
<h:outputLabel style="position:absolute;left:200px;top:100px;" value="New appointment:"></h:outputLabel>
<br>
<br>
<h:inputText style="width: 259px;position:absolute;left:200px;top:120px;" binding="#{PatientsSearch.inputText1}" valueChangeListener="#{PatientsSearch.lookForName}" immediate="true" id="inputText1" />
<h:commandButton value ="Search patients by name:" style="width: 173px;position:absolute;left:465px;top:120px;" action="#{PatientsSearch.getPatientsByName}">
<f:param name="day" value="#{request.getParameter('day')}" />
<f:param name="month" value="#{request.getParameter('month')}" />
<f:param name="year" value="#{request.getParameter('year')}" />
</h:commandButton>
<br>
<h:panelGroup id="pn_DETAILS_GRP" style="overflow:auto;position:absolute;top:155px;left:200px;width:300px;height:150px;solid black">
<h:dataTable id="tb_USER_DETAILS" border="1" var="patient" value="#{PatientsSearch.patients}" style="width:300px;height:150px" rowClasses="oddRow, evenRow">
<h:column id="name">
<f:facet name="header">
<h:outputText value="Name" style="font-size:10pt"/>
</f:facet>
<h:outputText value="#{patient.name}" style="font-size:8pt"/>
</h:column>
<h:column id="phone">
<f:facet name="header">
<h:outputText value="Phone" style="font-size:10pt"/>
</f:facet>
<h:outputText value="#{patient.phoneMobile}" style="font-size:8pt"/>
</h:column>
<h:column>
<h:inputHidden id="patientId" value="#{patient.id}" />
</h:column>
</h:dataTable>
</h:panelGroup>
<h:inputHidden id="testId" />
<br><br><br>
<h:outputLabel value="Choose doctor:" style="width: 200px;position:absolute;left:200px;top:325px;"></h:outputLabel>
<h:selectOneListbox style="width: 231px; height: 27px;position:absolute;left:400px;top:325px;" value="#{PatientsSearch.selectedDoctor}" size="1">
<f:selectItems value="#{PatientsSearch.doctors}" var="d"
itemLabel="#{d.name}" itemValue="#{d.name}" />
</h:selectOneListbox>
<br><br><br>
<h:commandButton value="Schedule" style="position:absolute;left:200px;top:430px;" action="#{PatientsSearch.scheduleAppointment}">
<f:param name="day" value="#{request.getParameter('day')}" />
<f:param name="month" value="#{request.getParameter('month')}" />
<f:param name="year" value="#{request.getParameter('year')}" />
</h:commandButton>
</h:form>
【问题讨论】:
-
您应该添加表单的其他部分,包括按钮。乍一看,这可能是验证错误的转换,您在某处有
h:messages吗? -
这个表格没有按钮? 所有其他按钮似乎都处于空闲状态,它们不再对点击做出反应。 哪些?
#{PatientsSearch.selectedDoctor}和#{d.name}的 getter/setter 是什么? -
嗨,你可以看到整个表格 - 我已经在上面添加了。有两个按钮,只有当我不选择 selectOneListbox 中的任何项目时它们才能正常工作。否则不会触发他们的回调。
-
两个按钮都会发送所有表单,这是您想要的吗?我怀疑当您选择医生时出现转换错误,是
#{PatientsSearch.selectedDoctor}和#{d.name}字符串? -
d.name 是一个字符串,PatientSearch.selectedDoctor 是一个医生类型。所以这个问题很可能是关于后者。我会把它变成一个字符串并检查。这就是您怀疑的问题所在,对吧?