I have three pages:
The first inserts some info into the DB.
The second inserts some new info into the DB, when it is requested
The third shows this information
How to notify the third page when the second updates the info?
Redirect to it from page 2 and append GET parameters such as http://www.your.url/page3?changed=true
Have a check on page 3 for parameters and behave accordingly.
Related
We render users in alphabetical fashion with 10 entries per page using will_paginate gem
Assuming we perform an action to activate or deactivate a user in the 2nd page (say user15)
, We would prefer to show user information on the 2nd page itself or should we redirect the user to the first page with default sort criteria here
There is another case where this is becoming problematic:
Assuming there are 31 entries, so 4th page will contain a single entry
, If we delete this user, we can't show the fourth page since no such user exists
In the above scenario, page=4 and per_page=10, but it would fail to render this page
How should we handle these scenarios, should we just show page=1 in any of the above scenarios.
What would be the right thing to do in the above scenario
We would prefer to show user information on the 2nd page itself or should we redirect the user to the first page with default sort criteria here
Can you elaborate on this one please.
Assuming there are 31 entries, so 4th page will contain a single entry , If we delete this user, we can't show the fourth page since no such user exists In the above scenario, page=4 and per_page=10, but it would fail to render this page
You might want to look into cursor pagination. Instead of pages, you have a cursor for the record and fetch everything before / after this cursor. This cursor could for instance be the encoded created_at timestamp.
Cursor pagination has a lot of other advantages over offset pagination too. However, will_paginate does not support cursor pagination so not sure if this is a feasible approach for you.
To get around these performance concerns, some database engines offer cursor-based pagination, or encourage pagination based on min/max values, e.g. WHERE id > :max_id in which the :max_id value is based on the previous page of results. This approach is usually superior for speed and memory concerns, but comes with some tradeoffs; the most notable being that it's only ever possible to go to the next page of results and not immediately jump to page 20, for example. The will_paginate library does not handle cursor-based pagination.
https://github.com/mislav/will_paginate/wiki
https://medium.com/#meganchang_96378/why-facebook-says-cursor-pagination-is-the-greatest-d6b98d86b6c0
I have an application where user authenticate himself in first page and later on move on to other pages.
Page 1 ( Authenticate & Save the credentials in variable)
|
Page 2 - Use the saved credentials & get the respective data from DB
|
Page 3 - Use the saved credentials & get the respective data from DB
|
Page n - Use the saved credentials & get the respective data from DB
So in the first page user will be Authenticate and he can move on to next page and the url will be like this:
http:\\ controller\Action1 --> Page 1
http:\\ controller\Action2 --> Page 2
Now, I want to make sure that user will not change the URL and jump to nth page from 1st page.. like..
http:\\ controller\Action1 --> Page 1
to
http:\\ controller\Action17 --> Page 17
As we are saving the credentials and he is authenticated user he can jump to any page he want to...I want to make sure that he follows the sequence ...In one single word..I dont want user to modify the URL and jump to any page he wanted...He should only modify to jump to NEXT PAGE not to any other page..
Background
I have a view page(abc.html.haml) with 2 drop down options A and B. A, B are lists which hold a set of records whose parts I am showcasing through the UI.
By default on hitting the controller#index action(called via browser url), the page populates with the records from the A list.
I then have an Ajax call which populates the same page with the records from list B, on choosing the drop down menu. Let's assume I have now moved from State A to B using the drop down option.
Issue
Once, I have the page populated with records from list B, Now, upon page refresh, My drop down menu still holds the same state 'B', but the default set of records which load from the controller#action on page refresh is from the list A(thus the state of the drop down menu should be 'A').
Any inputs on how I can get a work around for this ?
Thanks.
I am not sure if I understand your problem completely, but a few options I can think of:
Use javascript to change the URL when selections are made in the drop downs. You could add paramaters to the URL that could reflect the state of the drop downs, you could then parse these on load of the page.
Give the user a refresh button that you control, then you can send information back to the controller on refresh so that you load the right defaults.
Store the current users selections in the database via ajax calls as the user makes them. I don't know the context of your app, so I don't know how feasible this is. Then you could obviously load these on page load if they exist.
The simplest option however would be to reset all controls on page refresh, I think users expect that behaviour anyway.
Is the JSF 2.0 View Scope "back button" safe? e.g. if I store a model in View Scope and go from page 1, page 2, page 3, to page 4, modifying the model object along the way (via input fields), and then hit the back button twice to go back to page 2 and make changes (taking me again to page 3), will the model in view scope have only changes that were made when page 2 was originally rendered or will it have later pages' changes?
Oracle ADF had/has something called "process scope" that handles this by tokenizing what is placed into session, so each page has its own copy of the model.
To start, the view scope is bound to a particular page/view. Multiple views won't share the same view scoped bean. The view scope starts with an initial GET request and stops when a POST action navigates with a non-null return value.
There are in general the following scenarios, depending on whether the browser is instructed to cache the page or not and the JSF state saving configuration. I'll assume that the navigation between those pages took place by a POST request (as it sounds much like the "Wizard" scenario).
When the back button is pressed:
If browser is instructed to save the page in cache, then browser will load the page from the cache. All previously entered input values will reappear from the browser cache (thus not from the view scoped bean in the server side!). The behavior when you perform a POST request on this page depends further on the javax.faces.STATE_SAVING_METHOD configuration setting:
If set to server (default), then a ViewExpiredException will occur, because the view state is trashed at the server side right after POST navigation from one to other page.
If set to client, then it will just work, because the entire view state is contained in a hidden input field of the form.
Or, if browser is instructed to not save the page in cache, then browser will display a browser-default "Page expired" error page. Only when the POST-redirect-GET pattern was applied for navigation, then the browser will send a brand new GET request on the same URL as the redirect URL. All previously entered input values will by default get cleared out (because the view scoped bean is recreated), but if the browser has "autocomplete" turned on (configureable at browser level), then it will possibly autofill the inputs. This is disableable by adding autocomplete="off" attribute to the input components. When you perform a POST request on this page, it will just work regardless of the JSF state saving method.
It's easier to perform the "Wizard" scenario on a single view which contains conditionally rendered steps and offer a back button on the wizard section itself.
See also:
javax.faces.application.ViewExpiredException: View could not be restored
What scope to use in JSF 2.0 for Wizard pattern?
I've got a page that creates a ticket in our help desk system. It acts as a wizard with the following steps:
Step 1
User selects the customer from a dropdown list. There is a jquery onchange event that fires and generates the list for step 2 and hides the step1 div and shows the step2 div.
Step 2
User selects the location from a dropdown list. This is generated based on the customer selected in step 1. There is a jquery onchange event that fires and generates the list for step 3 and hides the step2 div and shows the step3 div.
Step 3
User selects the type from a dropdown list and enters text into 3 different text boxes. If the user fails to enter text or enters invalid text my controller changes the model state to invalid and returns the view.
How can I get all the dropdowns to repopulate again with the correct selection the user chose and get the page to redisplay on Step 3?
My first thought was to use ajax and when the user clicks the Create button, I could create the ticket from there and if successful send them to the ticket detail. If unsuccessful, well just display an error message and i'm still on the page so no big deal. Now that I write it out I think this is best. Are there any major issues using ajax? It seems most sites use some type of javascript or ajax these days.
Second thought is to not use ajax at all and submit all the pages to the server.
What do you suggest?
The 3 steps display completely different markup.
There is possibly not much you can gain by an AJAX-version, except the avoided page flicker when you change the steps.
If you go the non-AJAX way you gain:
nice bookmarkable links ( www.ticketsystem.com/Customer -> www.ticketsystem.com/Customer/Microsoft/ -> www.ticketsystem.com/Customer/Microsoft/Location -> www.ticketsystem.com/Customer/Microsoft/Location/Redmond )
browser history works
easier testing
To redisplay the lists after step 3 you would load all of them and set the selected item according to the parameter in the URL.
I agree with you. Use AJAX to submit the ticket.