You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Anand <10...@gmail.com> on 2010/01/08 14:16:36 UTC

Server side error messages need to be cleared when resubmitted the page to prevent duplicate display

Hi All,
We are facing some issues related the client side validation error messages.

Let's say we have two text boxes a1 and a2 in an xhtml file
1. a1 has client side validation
2. a2 has server side validation
User fills in correct data in a1 and wrong data in a2 and submits the
request. Server side validation for a2 render appropriate error message on
the page. Now, the user inputs correct data in a2. But he decides to change
the data for a1. This time s/he accidentally enters wrong data in a1 and
submits the request.

Result: The faces message box/control is updated with the error for a1 due
to client side validation along with the previous error message for a2 as
well. Actually, the request never reached the server due to client side
validation on the a1 text box getting evaluated prior to sending the
request. And hence, the earlier server side validation message is also
retained and shown on the page. This can be confusing for the end user as a2
has correct data.
Our application uses Trinidad 1.2.12.

We would like to flush server side faces message, whenever user re-submits
with correct value in a2, such that previous messages are not retained and
shown.

How we can achieve this? Is there a way to to clear the faces messages on
clicking submit button by programatically calling any Trinidad JavaScript
API?
-- 
Thanks,
Anand

Re: Server side error messages need to be cleared when resubmitted the page to prevent duplicate display

Posted by Yannis BRES <ya...@gmail.com>.
Hi !

We also faced this issue, and the quickest / less dirty way we found to
address it was to write a small Java Script method, that gets called on all
form submissions using onsubmit :
  <tr:form id="smc_domain_form"
          onsubmit="SMCClearAllMsg();return true;">

This method first removes the global messages that are in displayed by
<h:messages
id="smc_global_messages" globalOnly="true" .../> and then removes whatever
non global messages that can appear on the page :
  function SMCClearAllMsg()
  {
      // remove global messages (with its list bullet)
      var global_msg= document.getElementById("smc_global_messages");

      if (global_msg != null)
      {
          global_msg.style.display='none';
      }

      // remove each message but do not remove client-side validation from
trinidad.
      // Note: only our messages where we set class=OraInlineErrorText are
involved
      // message generated by client-side validation usually have class=x9e
(compacted).
      var spans = document.getElementsByTagName("span");
      for ( var i = 0; i < spans.length; i++)
      {
          if (   (spans[i].className == "OraInlineErrorText")
              && (spans[i].parentNode.className !=
"af_panelFormLayout_message-cell")
              && (spans[i].parentNode.className !=
"AFComponentMessageCell"))
          {
              spans[i].style.display = 'none';
          }
      }
  }

Of course, the question remains :  shouldn't this be done by Trinidad ?

Hope this helped,
         Yannis