![](/img/trans.png)
[英]jsf1.2 rich:messages duplicating validation of rich:message in the same form
[英]JSF1.2 Messages not rendered
从WAS6.1 + JSF1.1 + richfaces.3.1.5迁移到WAS7 + JSF1.2 + facelets1.1.14 + richfaces3.3.3。
即使在调试facescontext.getMessages()包含消息后,也不会使用h:messages呈现错误/状态消息。
在提交表单时,我正在验证输入。 如果验证失败,则向facescontext添加一个错误消息。 它可以用于多个输入。 每个错误消息都添加到facescontext
FacesMessage message = new FacesMessage();
message.setDetail(msg);
message.setSummary(msg);
message.setSeverity(FacesMessage.SEVERITY_ERROR);
getFacesContext().addMessage(componentID, message);
在xhtml上,我使用h:messages显示它
我在WAS6.1和JSF1.1中使用了jsp,这以前工作正常,谢谢
添加更多详细信息
我的xhtml
<ui:composition template="/template.xhtml">
<ui:define name="content">
<div id="content-nosidebar">
<h:form id="uploadDoc1" >
<h:messages/>
<h:panelGrid id="panelGridContact" headerClass="standardPageHeader" width="100%" cellpadding="5">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Upload Contact Info" />
<hr/>
</h:panelGroup>
</f:facet>
<h:panelGroup id="msgId">
<xyz:errorMessages />
<xyz:statusMessages />
</h:panelGroup>
<h:panelGrid style="text-align: center;font-weight: bold;">
<h:outputText value="Click on Browse button to identify CSV file with contact information for upload."/>
<h:outputText value="File size limit is 10MB."/>
<h:panelGroup>
<rich:fileUpload id="fileuploader" fileUploadListener="#{uploadContactCntrl.onSubmit}"
acceptedTypes="csv" allowFlash="true" listHeight="50" addControlLabel="Select File" uploadControlLabel="Submit" clearControlLabel="clear"/>
</h:panelGroup>
<h:outputText value=" "/>
</h:panelGrid>
</h:panelGrid>
</h:form>
</div>
</ui:define>
</ui:composition>
errorMessages和statusMessages是显示错误(验证错误)和状态(例如更新完成)消息的常用标记
在提交时,如果遇到错误(例如“找不到文件”或“数据库已关闭”),我将使用资源文件中的错误/状态消息调用通用方法。
WebUtils.addCustomErrorMessage(“ global.error.ContactInfo-DuplicateRecords-UserID”,新的String [] {userid,Integer.toString(j + 1)},Constants.RESOURCE_BUNDLE_NAME); 或WebUtils.addCustomStatusMessage(“ global.error.ContactInfo-successMessage”,新的String [] {Integer.toString(noOfRowsInserted)},Constants.RESOURCE_BUNDLE_NAME);或
public static void addCustomErrorMessage(String msg, String componentID) {
FacesMessage message = new FacesMessage();
message.setDetail(msg);
message.setSummary(msg);
message.setSeverity(FacesMessage.SEVERITY_ERROR);
getFacesContext().addMessage(componentID, message);
}
public static void addCustomStatusMessage(String msg, String componentID) {
if (errorCodeParameters != null && errorCodeParameters.length > 0)
msg = MessageFormat.format(msg, (Object[])errorCodeParameters);
FacesMessage message = new FacesMessage();
message.setDetail(msg);
message.setSummary(msg);
message.setSeverity(FacesMessage.SEVERITY_INFO);
getFacesContext().addMessage(componentID, message);
}
当在输入字段上遇到错误时,我们也使用相同的标记来显示错误消息。 例如,名字字段包含无效字符。
如前所述,在迁移到JSF1.2之前,此方法工作正常
您的答案也需要具有xhtml代码,无论如何,我都会给您提供在JSF 1.2中使用验证的示例...
xhtml代码应该像..
<h:inputText id="txt_project_name"
value="#{FIS_Project_Master.txt_project_name_value}"
validator="#{FIS_Project_Master.txt_project_name_validator}"/>
<h:message id="msg_txt_project_name" for="txt_project_name" />
Java代码应该像...
public void txt_project_name_validator(FacesContext context, UIComponent component, Object value) {
if (bmwpProjectMstFacade.ispmProjName_exists(value.toString().toUpperCase().trim())) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_WARN, "Warning", "Project Name Already Exist");
throw new ValidatorException(message);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.