我希望我的面板保持可见状态,当我点击命令按钮并且执行的方法调用错误消息时。防止rich:popupPanel点击命令按钮后关闭
更具体地说,我有一个输入字段的验证器,它应该会得到一个日期。如果这个日期无效,我的支持bean中的validate方法会创建一条错误消息。这应该显示在使用命令按钮后弹出面板中的输入字段旁边。
点击命令按钮关闭弹出窗口。但是如果我重新打开它,会显示错误消息,这让我不知道为什么它在第一时间关闭,而最大严重性条件未得到满足。
我的XHTML页面:在支持Bean
<h:body>
<h:commandButton id="note" value="Neuer Satz">
<rich:componentControl target="note_panel" operation="show" />
</h:commandButton>
<rich:popupPanel id="note_panel" modal="true" autosized="true"
resizeable="false" header="Neuen Mehrwertsteuersatz vormerken"
domElementAttachment="form">
Gültig ab
<h:inputText id="newVorGueltigAb"
value="#{mehrwertsteuerBean.neuGueltigAb}" maxlength="10"
validator="#{mehrwertsteuerBean.validateNewDate}" />
<h:message for="newVorGueltigAb" style="color:red" />
<h:commandButton value="Vormerken"
action="#{mehrwertsteuerBean.addSteuersatz()}"
oncomplete="if (#{facesContext.maximumSeverity==null})
#{rich:component('note_panel')}.hide(); return false;" />
<h:commandButton value="Abbrechen"
onclick="#{rich:component('note_panel')}.hide(); return false;" />
</rich:popupPanel>
</h:body>
我的验证方法:
所有的public void validateNewDate(FacesContext context, UIComponent toValidate,
Object value) {
String regex = "([0-9]{2}).([0-9]{2}).([0-9]{4})";
String date = (String) value;
if (date.matches(regex)) {
validNewDate = true;
} else {
validNewDate = false;
String message = "Bitte gültiges Datum eingeben!";
context.addMessage(toValidate.getClientId(context),
new FacesMessage(message));
}
}
h:commandButton没有'oncomplete'属性。 – Makhiel
噢,好的,谢谢! 但是,如果我使用a4j:commandButton出现另一个问题: 如果我尝试提交错误的日期弹出不会按要求关闭,但不会显示错误消息。 – Marco
你必须渲染消息的地方。 BTW。只有在验证newVorGueltigAb失败时才会显示。因此,请查看整个表单的'h:messages'或'rich:messages'。 BTW2。如果你想验证失败,你必须抛出'ValidatorException'。 –