What would be the best way to store a list in a GSP page - grails

I currently have a gsp page with pagination and bulk actions based off of checkboxes. I want to store the checked item ids as the user goes to the next page, but to do so I need to store the items the user has checked. I was wondering how I could store that in the GSP page?
Thank you.

I want to store the checked item ids as the user goes to the next
page, but to do so I need to store the items the user has checked. I
was wondering how I could store that in the GSP page?
You could store them in a GSP page simply by defining a variable in the page and assigning it a value of the ids, but that won't solve the problem you are trying to solve because that page will be gone by the time the user navigates to the next page.
Unless you are introducing some client side technology for managing state, a more common thing to do would be to submit the ids to the server and store them in a session or possibly in a database depending on the use case.

Related

Is it possible to let a user fill a google form in different sessions?

I want a form where the user can fill some values and then exit, and then come back in some time and complete the form and submit it. Is it possible with google forms? If so, will the data entered in the second session be saved along with the corresponding row in the spreadsheet or will a new row be entered?I hope my question is clear
Data from the Form only goes to the server when it is submitted, so you cannot store that form data before submission (disregarding any data that might have gotten stored in the browser session).
What you could do instead is select Settings and check the option Edit after submit. This way, a user can submit the Form and then come back later to edit the responses.
Reference:
Google Forms: Allow people to edit responses

Making sure only one user is editing a form in Rails application

Currently, I have a Rails application whose edit form is on a separate edit page. Is there a way to make sure no two users are accessing the edit page at the same time? Or a user can only access the edit page if no other user is currently on the page?
Or to ask a simpler question, is there a way to get a list of users currently on the page?
I am on Rails 4.
HTTP is a stateless protocol. It was designed to allow idempotent transactions. The server does not store transaction state information about each chain of requests. The session allows you to mitigate this design pattern and allow the server to track where your users have been. In order for you to know if a user is on a page, you will need to store in your database where each user is. Remember, that when a user decides to navigate away from a page, your servers will not know it, only when a request is made to a different page.
I assume you don't need to track anonymous session information, so you probably need to override your controller action that ensures users are logged in to save where the user is at. Before rendering the page, ensure the count of user's current location equal to the rendered page is 0.
You can have AJAX fire on the page, updating the location of your user on these pages so you can ensure that there has been no user in a reasonable timeout. Without the AJAX you would need to consider what the reasonable amount of time a user would be editing information, and consider that a non-reasonable amount of time is likely the actual amount.
There's no 'RAILS' feature that can be turned on to check where a user is located, this would be a roll your own situation.
I think the best way is to use a Redis Store (or anything in memory), or make a temporary sessions table for that.
Then you can authorize the show action to check whatever you want.

Ruby on Rails: Two views, one save buffer

Just a note before you read this, I'm not a programmer in RoR but I just wanted to validate that this is possible, so sorry in advance.
I have a quick question about using a secondary page. Here's how I want it to work:
I have a primary page that has some data that will be saved. I have a link to a secondary page that you save only to the buffer. This means that if I change it three times everytime i go back to look at it it shows the last value I changed it to.
At save time of the primary page, I want the information on the primary page and the secondary page to be validated and saved. If it fails, I don't want to save the information on either page. Is this possible in RoR? If so can someone explain to me how?
You could do this in a few ways:
Have one real page, but use JavaScript to hide and show parts of it as needed.
Store the object in the session, and only write it to the database at the end
Store the data in a temporary table and save it in the real table at the end

Keep some information between different "new" forms

I have a form where the user can choose options from a lot of select boxes. The form is used to register several items from an RSS feed. The user fills in the form, clicks create and is presented with the same form for the next item in the list.
Sometimes, the same options are valid for several items in the list, and I would like to be able to save some of the selections done so the user doesn't have to make the same selection for the next items.
What is the best way of doing this? I've identified four ways of doing it:
Sessions
Just keep the values in the session hash. This will of course work and is very simple, but I have some undefined feeling that it is a bad idea. It will also not work if the user is using the form from different tabs in the browser.
Cookies
Basically the same as keeping them in the session, I think.
Profile
Can't be done in this case I believe, since profiles are shared between several users.
Database
The most complex way I've come up with is to keep the information in the database and use a query parameter to keep track of which information should be used. This is probably overkill, but in some ways the best way to me. I don't like the idea of keeping this kind of state in session or cookies.
Am I missing some way? Or something?
If after filling first form, some data is saved to db (object is created) then you can use this data from db to fill up new form.
If after filling first form, nothing is saved to db, then you can create in memory some objects based on params from previous post and based on this (on just on params) you can prepare new form. But of course data from previous form should be added as hidden fields in second form.

Storing Product List through out session

Im using MVC ASP.NET C#, jQuery
I'm building what could be decribed as the simpliest shopping cart in the world.
Basically My Clients wants users to be able to browse the site, Click on a product they want and it be added to a "list" and then when they "Checkout" they simply fill in a form and it emails my client with the list of products they had chosen!
I was thinking of something like storing them in a cookie. So as the user browses they won't be lost, Then have a jQuery dialog appear when they choose to view/checkout their cart. and it can list all products and then they simply fill in a simple form..
Is this the best way to go about it. Its a cheap website and I would like the simplest way to do this? All i guess I would need to sort is the product Id's..
Any ideas of better ways or any opinions at all!
Using Session depends on whether you think the users will pick the products in one go. Or will they leave the page and come back in an hour? The problem being that if they come back in an hour, the Session State may have been garbage collected to free up resources on the server, or the session might have expired.
To get around this, if all the products are on one page, you could store the chosen products in a hidden field, encrypted and all, that will stay there until the user closes the app.
You just need to serialize the list of product Ids, pass that serialized string to the view and put it in a hidden field.
Another option would be to store it in the users session. A benefit of this is if the user has cookies turned off and the site caters for cookieless session state then they will still be able to select products and checkout.
The thing to look out for is how much you could potentially end up storing in session. From the sounds of it this will not be an issue but if this could potentially use up an unacceptable amount of memory then you would probably need to consider a database approach anyway rather than cookies.
I'd say to go for the Session object. You can always configure the location of Sessions at runtime
I think some may dislike this storage method (it breaks testing isolation, if i'm not mistaken), but it's there for free :)
If you're using jquery, you could store the basket as a json array inside the $('body').data() element (or actually as i do, under a div called '#storage'). this works as a fantastic local storage mechanism, tho' would only be relevant to the current page that the user was on and would be cleared on moving to subsequent 'new pages' unless of course, your design was such that the shopping page was ALWAYS the same page and only refreshed by ajax methods. this way, you could continually append/modify the json structure on the 'worksurface' page.
i use this technique for a different application of the logic, but virtually for the same reason.
here's a snippet of the kind of thing i do:
/* example of data params key*/
var keyParams = "Data-Search-type-" + $('#searchtype').val();
/* add json to body with key*/
$('#storage').data(keyParams, jsonData);
/* get same data back later */
var jsonData = $('#storage').data(keyParams);
When i 'save' the data to the server, i then clear the data() element back to null. There is of course the other option of localstorage itself which can be used well, especially in disconnected environments (such as mobile apps).
another way to skin the many skinned cat!!

Resources