Scroll p:messages into view when it is updated and (error) messages are present

前端 未结 4 1284
暖寄归人
暖寄归人 2021-01-05 18:58

I am working with PrimeFaces messages, I want my whole page to scroll to top when p:messages is rendered.

4条回答
  •  遥遥无期
    2021-01-05 19:44

    Lets say that your button is causing the messages to appear.

    XHTML

    
    

    javascript

    //javascript function which scroll to the first message in page   
    function scrollToFirstMessage() {
         try {
            PrimeFaces.scrollTo($('.ui-message :first-child').eq(0).parent().attr('id'));
         } catch(err) {
           //No Message was found!
         }
      }
    

    Hope this helps.

提交回复
热议问题