我使用这两个primefaces标签来显示相同的自定义验证消息
<p:messages id="modalMessages" showDetail="true" autoUpdate="true"/>
<p:inputText id="permissionNumber" value="#{wizzardBean.client.permissionNumber}" validator="#{wizzardBean.validateClientPermissionNumber}"/>
<p:message id="permissionNumberMessage" for="permissionNumber" showSummary="true" display="icon"/>
<h:commandButton value="Confirm">
<f:ajax execute="clientPermissionInput" render="mainFormInputs modalDialog" listener="#{wizzardBean.submitClientPermission}"/>
</h:commandButton>
我需要在两个地方都显示摘要和详细信息。目前<p:messages>
显示摘要和详细信息,而<p:message>
仅显示详细信息,即使我已指定showSummary="true"
也不显示摘要。
showSummary="true"
工作<p:message>
还是错过了什么?
bean验证器:
public void validateClientPermissionNumber(FacesContext context,
UIComponent toValidate,
Object value) {
String permissionNumber = (String) value;
Pattern pattern = Pattern
.compile(PERMISSION_NUMBER_PATTERN);
Matcher matcher;
matcher = pattern.matcher(permissionNumber);
if (permissionNumber.isEmpty()) {
((UIInput) toValidate).setValid(false);
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Permission number required.");
context.addMessage(toValidate.getClientId(context), message);
} else if (!matcher.matches()) {
((UIInput) toValidate).setValid(false);
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Wrong permission number. ");
context.addMessage(toValidate.getClientId(context), message);
}
}