Creating Chaos in PrimeFaces Page Navigation with JavaScript

I have implemented third-party connection monitoring code called Online JS by Denis Radin and it seems to be causing unexpected interactions with the navigation elements on my webpage. I am seeking insight into possible reasons for this behavior in order to address the issue more effectively.

With the Javascript code in place, a PrimeFaces commandButton element intermittently fails - sometimes it redirects me to the desired page, while other times it does nothing.

    <p:commandButton
        icon="icon-back"
        value="#{appMsgs['button.back.to.inbox']}"
        rendered="#{viewBean.back}"
        actionListener="#{controllerBean.selectState}"
        update=":frmMain:mainContent" />

In addition, a PrimeFaces dataTable with a rowSelect listener also exhibits erratic behavior, occasionally redirecting me to an incorrect page when clicked.

    <p:dataTable
        id="widgets"
        value="#{cc.attrs.widgetList}"
        var="widget"
        widgetVar="widgetTable"
        rowKey="#{widget.widgetId}"
        selectionMode="single"
        <p:ajax
            event="rowSelect"
            listener="#{controllerBean.handleWidget}"
            update=":frmMain:mainContent"
            onstart="widgetTable.clearSelection()"
            process=":frmMain:txtInputTimeElapsed :frmMain:txtInputTimeRemaining :frmMain:mainContent" />
    ...
    </p:dataTable>

The problematic Javascript code below pings the server every five seconds. If the connection fails, a widget appears that disables the page and pauses any running timer. Once the connection is reestablished, the timer resumes, and the user regains access to the page. Any insights or suggestions on how these interactions could be causing issues would be greatly appreciated.

Besides the navigation problems, the JavaScript code functions perfectly otherwise.


Edit: Upon advice from BalusC, I replaced the old version with a jQuery implementation which improved the reliability of the commandButton. However, the rowSelect listener still tends to misdirect me to the wrong page.

Below is the updated concise code. The original JavaScript code is provided at the end of the post.


Edit 2: It appears that the issue lies within the e.ajax call. When I visit the dataTable page and wait for the e.ajax call to trigger before clicking on a row, it consistently directs me to the wrong destination.

Adding async:false to the ajax call not only fails to resolve the problem but also completely breaks the navigation functionality; the rows in the dataTable become unselectable.

Any suggestions on why Ajax and PrimeFaces are conflicting and how this can be rectified?

New jQuery Code:

[Updated jQuery code goes here]

Old non-jQuery Code:

[Previous non-jQuery code goes here]

Answer №1

Oh, I've found it!

The culprit is the ajax call - specifically, the ajax call to window.location. This interferes with the state of the backing bean (or something similar), causing navigational chaos.

Therefore, if anyone else encounters this issue, redirect the ajax call elsewhere.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The significance of Token Details in Tokbox

I'm currently working on developing a video chat platform that caters to various user roles - some may just observe while others actively participate in calls. I've been exploring the capabilities of the Tokbox Api () which allows metadata to be ...

Delete the current row in the table before adding a new one with jquery

Having a HTML table and performing updates using Ajax. Everything is functioning properly so far. When clicking on the Edit button, the values are displayed in the textboxes correctly. However, when clicking on the Add button, the table is updated accordin ...

Transform the default WordPress gallery into a stunning slideshow with FlexSlider 2 integration

Greetings, I am searching for a solution to modify the default WordPress gallery in order to integrate the FlexSlider 2 plugin. I specifically want to incorporate this module or feature from this link, but I have been unable to figure it out myself. Your ...

Bring in resources without specifying

Is there a way to directly import an image into a JSX tag in React without having to declare it at the top of the file using import img from './this/is/file.png'? I attempted to do so with <img src={import './this/is/file.png'} alt= ...

The HTML element <a> can have both a href attribute and a onclick attribute

I'm currently facing a challenge with my project - I am trying to create a submenu that includes all sub-pages within a single HTML file. However, whenever I attempt to use both href and onclick, the functionality fails to work as intended. The only ...

What steps are necessary to configure .eslintrc to identify the use of 'require'?

I recently started using ESLint and successfully integrated it with IntelliJ. Initially, ESLint did not recognize node out of the box. After consulting the documentation, I created a configuration file named .eslintrc at the project's root folder, sp ...

Tips for modifying a state array in Vuex

I have the ability to add and remove entries, but I'm struggling with editing. How can I achieve this using VUEJS, VUEX, and JavaScript? For adding entries, I know I should use PUSH, and for removing entries, SPLICE works fine. But what about editing ...

What are the implications of making more than 8 ajax calls simultaneously when a single submit button event is triggered?

I am currently working on a project that involves the use of 8 dropdown menus. These dropdowns are optional, meaning that users can choose to select all 8, or just a few based on their requirements. Each dropdown operates independently, and I have written ...

Scheduling a cron job to run at a particular date and time

Our express js application includes a feature in the admin module where users can send emails at specific dates and times they select. For example, if the chosen date and time is [email protected], we need to execute the email code at that exact time ...

I am interested in incorporating various forms within this code

I followed an online tutorial to create this code, and I've made some edits myself, mainly related to the buttons that display information. However, I'm still learning and struggling with adding different forms to each section. I would really app ...

Retrieving the Selector Value during a Change Event

Is there a way to retrieve the selector value in a change event? I attempted this approach: $("#frek_menonton_tv :input").change(function(){ $(this).selector; }); However, it only returns an empty string. Desired outcome: frek_menonton ...

A novel way to enhance a class: a decorator that incorporates the “identify” class method, enabling the retrieval

I have been given the task to implement a class decorator that adds an "identify" class method. This method should return the class name along with the information passed in the decorator. Let me provide you with an example: typescript @identity(' ...

Learn how to display specific text corresponding to a selected letter from the alphabet using Vanilla JavaScript

I am extracting text from a JSON file. My goal is to enable users to click on a specific letter and have the corresponding text displayed. For example, if someone clicks on 'A', I want to show the text associated with 'A'. An example of ...

Issue with JavaScript-generated dropdown menu malfunctioning in WebView on Android devices

During my testing of the app on a Galaxy Tab with Android 2.2, I encountered an issue within the WebView component. The problem arises when I have a local HTML page generated dynamically and it contains a SELECT element like this: <select class='d ...

Utilize the lodash times method for indexing

I have a requirement to duplicate a component "n" number of times. I achieved this by utilizing the lodash method called "times". However, I encountered an issue with assigning an index as a key for the generated components. Below is the snippet of code t ...

Updating a section of a webpage using jQuery Mobile

I'm currently facing an issue with modifying a specific section of my webpage. Although this problem has been discussed before, I haven't found a satisfactory solution yet. The element in red on the page needs to change dynamically based on the ...

Give a radio button some class

<input id="radio1" type="radio" name="rgroup" value="1" > <label for="radio1"><span><span></span></span>1</label> <input id="radio2" type="radio" name="rgroup" value="2" > <label for="radio2"><span ...

What is the method for invoking a function with arguments within an HTML `<p>` element?

I am looking to display like and dislike percentages on cards. <v-card v-if="software[2] == searched || searched == ''" class="software-card" > <h3>{{ software[2] }}</h3> ...

Styled-components causing issues with conditional rendering

Within my React component, I have multiple properties and I want styles to only apply if a property has a value. I attempted the following code: export const Text = ({text, color, size, fontFamily}) => { const StyledParagraph = styled.p` m ...

The expected functionality of sending files via ajax is not happening as anticipated

I am having issues with passing file data along with other inputs to my ajax function. Despite my best efforts, the server is not receiving the files. I'm fairly new to using ajax and Jquery. Below is the code snippet of what I have attempted so far. ...