从WAS6.1 + JSF1.1 + richfaces.3.1.5迁移到WAS7 + JSF1.2 + facelets1.1.14 + richfaces3.3.3。
错误/状态消息未使用h:消息呈现,即使在调试facescontext.getMessages()包含消息时也是如此。
在提交表单时,我正在验证输入。如果验证失败,我将向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是显示错误(验证错误)和状态((如更新完成)消息的常用标记
在提交的backbean中,如果遇到错误(例如“找不到文件”或“数据库已关闭”),我会使用资源文件中的错误/状态消息调用常用方法。
WebUtils.addCustomErrorMessage(“global.error.ContactInfo-DuplicateRecords-UserID”,new String [] {userid,Integer.toString(j + 1)},Constants.RESOURCE_BUNDLE_NAME); 要么 WebUtils.addCustomStatusMessage(“global.error.ContactInfo-successMessage”,new 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
之前,这工作正常答案 0 :(得分:0)
你的答案也需要有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);
}
}