• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Waiting on a Refresh

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following does not seem to work because of a lag between the reload and calling the servlet. If I put an alert between these and wait about two seconds it works fine. How can I fix this without the alert?

My JavaScript:

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you reload the current page, um...you can not call code to also submit that page.

It is like handing your plate to a waitor at a restaurant becaue you are done. Than you go back to eating off that same plate. You can not do it since the action of handing the plate to the waitor has taken the plate away.

Refreshing the page is removing the JavaScript. I am not sure why you need to reload a page than submit a form. Submitting a form will reload the page or redirect it.

Eric
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The form that is submited by the action uses data that was used to populate the submiting form. I need to make sure this data has not changed before the next page is displayed.

Example: A user types in a number, a form is displayed with data, options are given to make changes to the record that is displayed these options take the user to different pages. One of the options is a revision letter. Say the current rev is 'A' the next rev would be 'B'. They click a button and a form appears giving 'B' as the new rev based on the previous forms data, they fill out for the new rev. At this time the record is locked until the new rev is completed. Now suppose two people have the same record called up. One desides to make changes. The other users session will not know changes are being made unless the page is refreshed. I need this refresh to fire when the options to make changes on the page is clicked to make sure the latest data is current on the page.

I hope this makes sense.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn;t you try to figure this out on the server when the form is submitted. Such as a validation message saying something like: "The form has been edited by someone else while you were working on it. Please verify/make changes"

There is no way for JavaSript to refresh the page and perform a command inline since you would have to reinvent the page lifecycle of a browser.

Only way to submit the page would be to set a cookie, check the cookie on window.onload. If it is there, than you know to remove it and submit the page.

I rather rely on the server than the client.

Eric
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still not sure we are synced yet.

My current process.
The user types in a number, a servlet is ran and displays remote record data on the page. Several session attributes are set that control what the user can do with this record. Lets take one of the attributes the revision level. The session attribute revLev = 'A'. If the user desides to make a revision change they click a submit button on the page and another servlet is fired using the session attribute revLev value to determine the next revivion(this keeps the connection class from running twice to download the record data).

Now in the mean time a second user has typed in the same number(before the first user initiated their change). Unless the page is refreshed the changes the first user makes will not be known by the second users session.

What I need is the page to refresh the displayed page data thus refreshing the session attributes before the clicking of a button takes them to another page where that page is dependant on session attribute values.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you are trying to submit the form, you are submitting it on the current page, not the reloaded page. You basically built a nice race condiotion of what will happen first, the refresh or the form submit. The refresh will probbaly win since it has a jump start being first.

Lets say that the refresh wins the race each time. That means your code is equivilant to doing:



It will not get to that submit code. It is like you close a door and you try to walk through it!

When the page reloads it ends the page's life cycle and creates a new page. All variables are reset and the browser has no clue of anything ouside what was just rendered.

You need to break your logic up into two steps as I mentioned before.
Step 1) Refresh the page
Step 2) When the page loads you submit the form

or

Step 1) Post the form and make the server logic smarter.

Eric
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have came up with a solution although there is still room for error. When the initial page loads a session attribute is assigned which is the current time plus 45 seconds. If the user opens the page then clicks one of the buttons that submits a form the time is checked. If it has been more than 45 seconds the button will not work until the page is refreshed.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cannot see how your hokey delay solves your issue at all.

The problem you are having is well know and is known as a "dirty write". There are tons of patterns to solve this issue available on the web.

My advice is to solve the issue for real on the server rather than using bubble gum on the client.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On your advice I decided to run another connection look up on the submit function to check the status and stop the servlet from loading the next form if things have changed. Thanks for all your help today. I am sure I will have other issues as the days go by.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic