jsf1.2 rich:消息以相同的形式复制rich:message的验证

时间:2012-02-07 21:08:55

标签: java spring richfaces jsf-1.2

我正在使用JSF / Spring webflow& mvc应用程序准备注册页面。我在客户端添加了两个边验证,每个输入字段都有自己的rich:message,另一个在服务器端,注册bean响应为facescontext.addMessage()。我尝试测试验证时的问题,丰富:消息组件显示错误正确但丰富:消息也显示相同的错误。我想仅针对特定错误使用消息,例如数据库中已存在邮件。

my 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”,当我使用此属性时,重复验证停止,但我无法添加严重性错误。我的输出如下:

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.)]

另一个问题是我应该保留服务器端验证吗?

1 个答案:

答案 0 :(得分:1)

好的,这是一个解决方法:  首先,它的已知问题请参考jboss community

Hi guys,

We investigated the issue further by debugging the RichFaces JavaScript code.

We noticed that both the <rich:messages globalOnly="true" /> component and the <rich:message for="inputField" /> component bind to an "onMessage" event.

When the event is triggered on tab, the "onMessage" function in "message.js.faces" is triggered for both components.

    As you can see in the attached screenshots the function is called twice: once for both components. Other <rich:message /> components which have a "for" attribute related to other fields are not triggered, just as expected.
    In the JavaScript code, we can see that a check is performed on the availability of the "forComponentId" attribute. If this attribute is available, a validation message is rendered for the specified component id. If this is not available, a global message is rendered.
    But when a global message is rendered, we cannot see any check on the globalOnly attribute. So any message is rendered, regardless of this attribute. The attribute is nowhere to be found in the JavaScript code.

    We were wondering if this is the bug or if there is an other piece of code that is responsible for checking whether only global error messages may be displayed?

所以我玩过代码并注意到富有:消息只是在以下情况下选择消息:

  1. 如果 globalOnly =&#34; true&#34; clientId 为null或clientId为消息组件ID。
  2. if for =&#34; xxx&#34; 属性 已分配和消息已 client&amp; sourceID =&#34; xxx&#34;
  3. 如果没有 for =&#34; xxx&#34; 和 没有 globalOnly =&#34; true&#34; 属性然后分配任何消息也包含消息 null客户端ID。
  4. 我能够为此应用两种解决方案:

    仅包含一个内容的网页的第一个解决方案:消息;

    我的rich:messages标记只有 globalOnly =&#34; true&#34; 没有属性;

       <rich:messages id="msg" layout="list"
            style="font-weight:bold;color:#BDBDBD" 
            globalOnly="true">
            <f:facet name="errorMarker">
                <h:graphicImage url="/images/messages_error.png" />
            </f:facet>
        </rich:messages>
    

    我的bean发送带有id = null;

    的消息
    private void addSeverityError(String message)
        {
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage fMessage = new FacesMessage();
            fMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
            fMessage.setSummary(message);
            fMessage.setDetail("Validation error");
            context.addMessage(null, fMessage);
        }
    

    包含多个内容的网页的第二个解决方案:消息;

    我添加了一个隐藏的rich:消息作为桥接器,然后我的消息可以有隐藏的组件ID,并且在我只是通过我的rich:使用此id的消息来获取它之后不会为null。

    <rich:message id="nonExistClient" rendered="false"/>
    <a4j:form id="messagesForm">
        <rich:messages id="msg" layout="list"
            style="font-weight:bold;color:#BDBDBD" 
            for="nonExistClient">
            <f:facet name="errorMarker">
                <h:graphicImage url="/images/messages_error.png" />
            </f:facet>
        </rich:messages>
    </a4j:form>
    

    我已经通过FacesContext添加了如下信息:

    private void addSeverityError(String message)
    {
        FacesContext context = FacesContext.getCurrentInstance();
        FacesMessage fMessage = new FacesMessage();
        fMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
        fMessage.setSummary(message);
        fMessage.setDetail("Validation error");
        context.addMessage("nonExistClient", fMessage);
    }