HTMX sometimes redirects to a page fragment instead of placing it in the page - htmx

I'm using HTMX to replace a fragment of page every 30 seconds using the following code:
<ul hx-get="/refresh" hx-trigger="every 30s" id="today" hx-select="#today" hx-target="#today" hx-swap="outerHTML">
This works perfectly most of the time. However when I leave the page open I sometimes come back and find it has redirected to the hx-get url ("/refresh" in the example). So it's showing just the unstyled fragment and the url bar shows the fragment url.
I think this might be something to do with the behaviour that is intended to show errors when they occur, but the page shown isn't an error. I think was happened is that HTMX got a transient error (maybe a drop in my internet connection when my laptop went to sleep) then just redirected to the page to show it but by the time it loaded the error was gone.
Any way to fix this? Assuming my assumption above is correct I think I'd like to silently drop errors for this particular element rather than redirecting to them.
Thanks in advance!

Related

Caching Issue with App Within Minutes sheet pages

I have created simple AppWithinMinutes application and I added following velocity code at the end in “sheet” page just before the html tag ends:
<div>
#set ($title = $doc.title)
## OR #set ($title = $doc.name), depending if your pages have titles
#set ($newTitle = $title.substring(0,6) + "X" + $title.substring(7, $title.length()))
<h2>Applications with a tag: $newTitle</h2>
{{PagesByTag tagName=$newTitle}}{{/PagesByTag}}
</div>
PagesByTag is a macro that I created to list all pages that contains the tag of a new title that I calculated.
Problem is:
I have a page called “My Application” with a tag “SERVERX01”
I have created a page in my AppWithinMinutes called “SERVERD01”. So now when I visit page SERVERD01, it displays “My Application” and that is desirable behavior (when you hard refresh it, disappears… hard refresh again brings it back… So it seems to be a cache issue…)
Now when I create a page in AppWithinMinutes called “MYAAPPD21”. Now “My Application” shows up here as well… This is not expected since $newTitle now will be “MYAAPPX21” and there is no page with that tag… (Hard refresh to that page will make “My Application” disappear but now when I visit “SERVERD01” page, “My Application” is gone from there as well)
There seems to be a serious caching issue with “sheet” page. Can someone tell me how can I disable caching for AppWithinMinutes display (sheet) pages?
Thanks a lot
I found a solution. In case someone like me facing exact same issue.
There wasn't an issue with App Within Minutes. It was a macro I created PagesByTag It has cached property set to yes. That was causing tag result on the sheet page to cache and was displaying undesirable results.

(Karate) How to intercept the XHR request response code?

I am testing a login functionality on a 3rd party website. I have this url example.com/login . When I copy and paste this into the browser (chrome), page sometimes load, but sometime does not (empty blank white page).
The problem is that I have to run a script on this page to click one of the elements (all the elements are embedded inside #shadow-root). If the page loads, no problem, script is evaluated successfully. But page sometimes does not load and it returns a 404 in response to an XHR request, and as a result, my * eval(scrip("script") step returns "js eval failed...".
So I found the solution to refresh the page, and to do that, I am considering to capture the xhr request response. If the status code is 404, then refresh the page. If not, continue with the following steps.
Now, I think this may work, but I do not know how to implement karate's Intercepting HTTP Requests. And firstly, is that something doable?
I have looked into documentation here, but could not understand the examples.
https://github.com/karatelabs/karate/tree/master/karate-netty
Meanwhile, if there is another way of refreshing the page conditionally, I will be more than happy to hear about it. Thanks anyone in advance.
First, using JavaScript you should be able to handle shadow roots: https://stackoverflow.com/a/60618233/143475
And the above answer links to advanced examples of executing JS in the context of the current page. I suggest you do some research into that, try to take the help of someone who knows JS, the DOM and HTML well - and you should be find a way to know if the XHR has been made successfully or not - for e.g. based on whether some element on the page has changed etc.
Finally here is how you can do interception: https://stackoverflow.com/a/61372471/143475

ADF Essentials in Glassfish: AUTOSUBMIT and VALUECHANGELISTENER attribute makes a message appear in the Web Browser

I have a ADF project in Jdeveloper 11.1.2.4.0, one of my pages contains this:
<af:selectOneChoice label="HEllO" value="#{bean.data}" id="id1" autoSubmit="true" valueChangeListener="#{bean.createNewData}">
<f:selectItems value="#{data.list}" id="id2"/>
</af:selectOneChoice>
I deployed it to Weblogic and everything worked fine.
Then I deployed it to Glassfish using the ADF Essential libraries. And it seems to work fine, but there is a unsuspected behavior at any place where there is a attribute AUTOSUBMIT. Everytime the value of the component containing the AUTOSUBMIT="true" is changed I have this behavior...
Firefox: A message saying: "To display this page, Firefox must send
information that will repeat any acction..."
IE: A message saying: "To display the webpage again, the web browser needs to resend the information you've previously submitted.."
Chrome: It redirects to the back page.
Opera: It redirects to the back page.
EDIT: The same happen when I have PARTIALSUBMIT set to true. I realized that I have to have the valueChangeListener attribute in order to get message.
Autosubmit=true will make (by default) your page to resubmit entirely. You should use partial triggers to avoid this. Set the ID of this component to the 'partial Triggers' attribute of the component you want to refresh (form,table, etc.). You should set 'partialSubmit=true' to your first component.

How can I clear the PropertyModel's value when I hit back on my browser

I have a DropDownChoice with a PropertyModel in my page and I have some other actions which take me to different pages. Now when I click on the Back Arrow on my browser, I come to my page which has the DropDownChoice with the previously selected choice. I understand PropertyModel holds the value for me. But how can I get rid of it when I hit Back button and why is the onBeforeRender(both on the class as well the Component) not working when I hit the Back button. Please comment if my explanation is not clear enough. I am using Wicket 1.4.8
onBeforeRender doesn't work because it's never called. When you navigating using "Back" button, no new request are sended to your server, hence page rendering never occurs. The only way to solve your problem - is to use javascript.

Web part lost when page post back

Here is the brief detail of issue.
I have Page1 where I have put LinkButton. The LinkButton Has property PostBackUrl pointing to Page2.
When user is redirected to page2, I am using Page Load method to access controls from previous page & get the needed value. To make clear, I am using this approach becuase I cant use querystring.
Page 2 has 2 web parts on it. The web parts use data received in Page Load event from page1 and renders data.
This works perfect on first page load. When user clicks on a URL in page which posts back, the web parts gets lost.
Note that if I come directly to page2 without going at page1, then web parts are retained in the page and they are not lost.
Can anyone give me the clue of issue cause?
Thanks in advance.
Do you have any debugging enabled? you are most likely looking for values on page load that don't exist and might be getting exceptions that aren't handled properly.
I am not sure why but somehow code was throwing an exception when I tried to access the property Page.PreviousPage. Though I had made sure to check null on each step. Even code was never get hit when web part was lost. So it is still a mystery for me.
Just in case someone comes across this issue my workaround may help. I used Post back to page2 using post method. I accessed the variables using Page.Form[] variables. This way my issue of getting web parts lost got resolved.