0

I have a page that displays orders, each order has a status of "Read/Unread". When you click the order id, you are redirected to a new page to visualize the PDF order. From the PDF file, you have a back button that takes you back to the page with the table of orders, and there the status of the order you just visualized has to be changed from "Unread" to "Read".

The issue: if you click the "back" button immediately after reaching the PDF visualization, the status of the order is not updated because the DOM is not updated so fast. Only after you refresh manually the page you can see the changed status.

I was thinking to add a delay on the back button until DOM is updated. (tried to reload the page automatically but doesn't look good).

The only problem is that I can't delay the button. I tried using the setTimeout directly in the onComplete, also tried to define a function in <script></script> and call it with setTimeout..not sure why is not working.

Here is my code:

    <g:documentViewer value="#{cc.attrs.value.viewer}" rendered="#{cc.attrs.value.viewer!=null}">
                    <f:facet name="actions">
                        <p:commandButton id="backbtn"
                                         value="#{'back'}"
                                         immediate="false"
                                         process="@this"
                                         update="@(.docPnl)"
                                         styleClass="#{'btn btn-primary'}"
                                         oncomplete="setTimeout(9000000); updateColumns(true); resetOrderBy();">
                                         
                            <f:setPropertyActionListener target="#{cc.attrs.value.viewer}" value="#{null}"/>
                        </p:commandButton>
 </g:documentViewer>
Maria
  • 57
  • 1
  • 6
  • Please read https://stackoverflow.com/questions/25947790/real-time-updates-from-database-using-jsf-java-ee – Jasper de Vries Dec 15 '22 at 15:12
  • `setTimeout()` doesn't block the current thread. It takes a callback function as 1st argument. It goes like `setTimeout(() => { updateColumns(true); resetOrderBy(); }, 1000);`. Give it a try. Coming back to the real problem which you attempted to solve in a somewhat wrong way, the link posted by Jasper above is the correct way to salvage the real problem. For instance, the `setTimeout()` work around namely won't work when you have the same page open in multiple browser windows. Those in other windows will still stay behind until you manually refresh it. – BalusC Dec 15 '22 at 20:06

0 Answers0