【发布时间】:2014-08-12 19:46:01
【问题描述】:
由于以下密切相关的问题已有一年半的历史,我想我应该重新问这个问题。 Keep <p:dialog> open when validation has failed
我在<p:dialog> 中打开了一个表单。如果正确输入并提交表单,一切都很好。如果用户提交无效信息,表单将保持打开状态,并且验证消息会按预期显示。但是,用户现在更正了表单并提交: 对话框关闭(很好,表单上不再有任何错误),但没有调用 commandButton 的 action 或 actionListener 方法。这是我仔细遵循链接问题的代码。
<h:form>
...
<h:commandButton value="Add Event..." onclick="addEventDlg.show()" type="button"/>
</h:form>
<p:dialog id="dlg" header="Add Event" widgetVar="addEventDlg" modal="true">
<h:form id="addEventForm">
<h:messages style="color:red;margin:8px;" />
<table>
<tr>
<td style="vertical-align:center"><h:outputLabel for="eventType" value="Event Type: " /></td>
<td>
<h:selectOneListbox id="eventType" value="#{addEventBean.eventType}" required='true' requiredMessage="#{msgs.eventType}">
<f:selectItems value="#{addEventBean.eventTypes}" var="etype" itemLabel="#{etype.name}" itemValue="#{etype}"/>
</h:selectOneListbox>
</td>
</tr>
<tr>
<td><h:outputLabel for="title" value="Event Title: "/></td>
<td><h:inputText id="title" value="#{addEventBean.title}" required="true" requiredMessage="#{msgs.eventTitle}"/></td>
</tr>
<tr>
<td><h:outputLabel for="occuranceDate" value="Event Date: " /></td>
<td><p:calendar id="occuranceDate" value="#{addEventBean.dateOfOccurance}" required="true" requiredMessage="#{msgs.eventOccuranceDate}" mode="popup"
showOn="button" showButtonPanel="true" pattern="yyyy/MM/dd" navigator="true" size="10"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<table>
<tr>
<td><p:commandButton value="Cancel" onclick="addEventDlg.hide()" type="button"/></td>
<td><p:commandButton value="Submit" action="#{addEventBean.addEventAction()}" type="submit"
update="addEventForm"
oncomplete="if( !args.validationFailed) addEventDlg.hide()"/>
</tr>
</table>
</td>
</tr>
</table>
</h:form>
</p:dialog>
我的 addEventBean 的 action 方法使用的是注入 bean 的控制器。
public String addEventAction() throws PersistenceException {
Event e = ECPEvents.getInstance(eventType);
e.setActualDate( dateOfOccurance);
e.setName( title);
return controller.insertEventAction( e);
}
上一篇文章使用了commandButton 的actionListener。我想用行动。我已经尝试了两种行为都没有改变。
我正在使用 mojarra 2.2、primefaces 3.5 和 tomcat 7。
有什么想法吗?提前谢谢你。
【问题讨论】:
标签: jsf-2 primefaces