jsf1.2 rich:messages 以相同的形式重复验证 rich:message
我正在准备使用 JSF/Spring webflow&mvc 应用程序的注册页面。我添加了两个侧面验证,一个在客户端,每个输入字段都有自己的 rich:message,另一个在服务器端,注册 bean 响应为 facescontext.addMessage()。当我尝试测试验证时,我的问题是,rich:message 组件显示错误正确,但 rich:messages 也显示相同的错误。我想仅针对特定错误使用消息,例如数据库中已存在邮件之类的消息。
我的 rich:messages 标签:
<rich:messages id="msg" layout="table" limitRender="true"
style="font-weight:bold;color:#BDBDBD">
<f:facet name="errorMarker">
<h:graphicImage url="/images/messages_error.png" />
</f:facet>
</rich:messages>
<h:form ...>
.....SOME LOGIC.....
<h:inputText id="i_ln" required="true" value="#{regBean.lastName}">
<f:validateLength minimum="2" maximum="35" />
<rich:ajaxValidator event="onblur" />
</h:inputText>
<rich:message for="i_ln">
<f:facet name="errorMarker">
<h:graphicImage url="/images/messages_error.png" />
</f:facet>
</rich:message>
.....
</h:form>
我已经检查了人们建议使用 globalOnly="true" 的类似问题,当我使用此属性时,重复验证会停止,但我无法添加严重错误。我的 oytput 如下:
Feb 07, 2012 10:08:04 PM com.sun.faces.lifecycle.RenderResponsePhase execute
INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=i_comment[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_title[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_salut[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_mobile[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_fax[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
另一个问题是我应该保留服务器端验证吗?
I am preparing a registration page using JSF/Spring webflow&mvc application. I have added two side validation one in client side every input fields has its own rich:message and other one at server side, registration bean response as facescontext.addMessage(). My problem when I try to test validation, rich:message components show errors correct but rich:messages show same errors as well. I want to use messages just for specific errors, something like mail already exist in database.
my rich:messages tag:
<rich:messages id="msg" layout="table" limitRender="true"
style="font-weight:bold;color:#BDBDBD">
<f:facet name="errorMarker">
<h:graphicImage url="/images/messages_error.png" />
</f:facet>
</rich:messages>
<h:form ...>
.....SOME LOGIC.....
<h:inputText id="i_ln" required="true" value="#{regBean.lastName}">
<f:validateLength minimum="2" maximum="35" />
<rich:ajaxValidator event="onblur" />
</h:inputText>
<rich:message for="i_ln">
<f:facet name="errorMarker">
<h:graphicImage url="/images/messages_error.png" />
</f:facet>
</rich:message>
.....
</h:form>
I have checked similar issues that people advice to use globalOnly="true" and when I use this attribute then duplicate validation stops but I am not able to add severity error. My oytput as below:
Feb 07, 2012 10:08:04 PM com.sun.faces.lifecycle.RenderResponsePhase execute
INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=i_comment[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_title[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_salut[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_mobile[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
sourceId=i_fax[severity=(ERROR 2), summary=(Eingabe wird benötigt.), detail=(Eingabe wird benötigt.)]
Another question is should I keep server side validation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这是一个解决方法:
首先,它是一个已知问题,请参阅 jboss 社区:
所以我玩过使用代码并注意 rich:messages 在以下情况下仅选取消息:
已分配且消息具有 client&sourceID="xxx"
没有分配 globalOnly="true" 属性,则任何消息也包含
空客户端 ID。
我能够为此应用两种解决方案:
第一个解决方案,仅包含一个 rich:messages;
我的 rich:messages 标签只有 globalOnly="true" 并且没有for属性;
我的 bean 发送消息 id=null;
针对具有多个 rich:messages 的页面的第二种解决方案;
我添加了一个隐藏的 rich:message 来用作桥梁,然后我的消息可以具有隐藏的组件 ID,并且将不为空,在我使用这个 id 通过我的 rich:messages 拾取它之后。
我通过 FacesContext 添加了如下消息:
Ok here is a workaround:
First of all its a known issue refer to jboss community:
So I have played around with code and notice that rich:messages just picking messages when:
assigned and message has client&sourceID="xxx"
no globalOnly="true" attribute assigned then any message also messages with
the null client id.
I was able to apply two solution for this:
First solution for pages with just one rich:messages;
My rich:messages tag just have globalOnly="true" and there is no for attribute;
And my bean send message with id=null;
Second solution for pages with more than one rich:messages;
I have added one hidden rich:message to use as a bridge, then my message can have hidden component id and will not be null, after I just pick it up by my rich:messages using this id.
And I have added message as below via FacesContext: