4

I am working on JSF application in primefaces in that i am showing an information to the user via <p:messages> .

So when the user click submit the page will processed and the p:messages dialog will triggered to show the information to the user ,

I referred Primefaces p:messages showcase Page

It is working fine..But after it displayed the messages , it is not closing automatically either we need to close that dialog manually or it remains in open stage.

I need it should it close automatically after it displayed the message to user... How can i do that ...Can anybody give suggestion that how can i do ?

kark
  • 4,763
  • 6
  • 30
  • 44

4 Answers4

8

<p:messages id="msgs"> is ultimately rendered as <div id="msgs"> and its contents is then updated with the factual messages to the user.

If you want to clear the message screen after some delay you should use the JavaScript setTimeout function after ajax call has been completed:

<p:commandButton ... 
        oncomplete="setTimeout(function() { $('#msgs").html(''); }, 3000);" />

The second parameter of setTimeout function is the delay in milliseconds.

The other alternative is to use <p:growl> instead.

skuntsel
  • 11,624
  • 11
  • 44
  • 67
  • @skuntsel.. Its not working but http://stackoverflow.com/questions/14210116/how-to-hide-close-the-error-message-automatically-while-using-pmessage working well, here `$('#msgs').html('');` by this code what will happen – kark Oct 10 '13 at 06:06
  • In what respect is it different apart from the fact that I remove HTML content while Daniel/Partlov decided to make it invisible and my code explicitly passes an anonymous function instead of literal text that's wrapped implicitly into an anonymous function? Solution was by the way tested on PF 3.5. – skuntsel Oct 10 '13 at 06:18
2

Worked for me for <p:fileUpload>, which was in <p:dataList> and <h:panelGrid> elements.

    <p:fileUpload...
           oncomplete="setTimeout(function() { $('[id$=mr-upload-messages]').hide(1000); }, 2000);">

...
    <p:messages id="mr-upload-messages" showDetail="true" showSummary="false" closable="true"/>

I have used jQuery $('[id$=mr-upload-messages]' to find id's which ends with mr-upload-messages, because Primefaces adds it's unique identifier at the beginning of id.

yyunikov
  • 5,719
  • 2
  • 43
  • 78
1

$('#msgs').html(''); immediately hide in 3 seconds but if you want to hide slowly as jquery hide method do this..

<p:commandButton ... 
        oncomplete="setTimeout(function() { $('#msgs').hide(1000); }, 3000);" />

hide(1000); hiding motion will be completed in 1 second

Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40
Mohsin AR
  • 2,998
  • 2
  • 24
  • 36
  • great Mohsin, this works fine to hide the message. I need to hide the popup as well as hide the message in 3 sec so in this case only the first method (hide popup) work which is quite strange! – Athar Jan 13 '17 at 18:25
-2

I came across the attention, and did it this way:

function hideMsg(){
$("#msg").delay(1000).hide(1000);
}

oncomplete="hideMsg()"