I'm having a table with the contents retrieved from my MYSQL DB. Now, below the TH row I have a row for searching through the table column wise. I have shown a sample search through the table.
The user of this application might check some checkboxes after doing some search (and according to some rules that satisfies research requirements). Now, I would like to have a submit [update records] button below this table which on clicking updates the corresponding records - against which the checkbox has been selected to update the value of CheckBox column - "Accepted"in this case.
For you information, I'm using struts and so to do this I will have write a struts action class to handle this. I also considered AJAX to update this asynchronously in the back-end. I would like suggestions from people on the best practice to do this.
Given the stack you have described, you have a web application with Struts on the server. When a user chooses to update the records you can either post the data using a html form, or use Ajax calls. Irrespective of how the data is sent, you will have Struts code to process the information and update the database. The only difference is in how the data got there. It's up to you to decide which makes more sense.
Related
I have to solve this situation: in my Spring + JPA web application I have a jsp similar to an excel work sheet.
So I have a certain number of cells and each cell is saved in a DB table with additional information: I have a row for each cell.
id | value | column | row | ...
I use this structure because number of columns in my jsp table is dynamic.
At the moment, when I save cells I truncate the current set of rows in DB table and re-insert all the new rows. This is the fastest way I found to update a large set of rows.
But now I have a concurrency problem: the jsp page can be used by different users at the same time and this can cause overwriting problems on other users savings.
I need to implement some kind of lock in my web app. I found there are mainly two types of lock: optimistic vs pessimistic.
Can you suggest me a common approach to solve this situation? Where do I need to implement the lock, at data access level or at service level?
NOTE to be more clear: table values are shared among users, but can be updated by anyone among authorized users.
The solution would probably depend on the behavior requirements.
How about the following scenario: users A and B started to change some values, then user A pressed Save button and saved data, after that user B did the same. User B got an error message saying something like "the data has been updated, please reload the page". He reloads the page and lose all changes he did :( Only after that he is able to save his changes, but he has to do it once again.
Other possible scenario: users A and B accessing the page, but only the user who was the first will be able to save his work, other users will see message saying something like "someone else is editing the page, try again later".
For the first scenario you can implement the following: each line of the table (in database) has a last-update-timestamp which is updated to current time each time this row is changed.
Now, let's imagine user A get row with timestamp 1 when opened the page, user B was a little bit slower and got the same row with timestamp 2. But, he did his changes faster and pressed Save button first. Now, the row is saved in DB with timestamp let's say 5. User A is trying to save his changes, but the timestamp of his data is 1, which is different from 5 currently in DB. That means someone changed that data already and he should see error message I mentioned above.
Second scenario is a little bit harder to implement. I think the best way to do this is to open transaction to DB which
reads the row(s) we want;
put some flag like "locked" to true for all of them;
if some row is locked already, fails (or return available rows, depending on what you need). But, probably should fail;
returns rows to jsp page;
Now, if other user requested the same rows, transaction will fail and he will not be able to start changing data.
User A should put these locked flags back to false when he saves the data.
Important thing: these locks should have timeout to prevent situation when user opened the page and closed it without saving (or browser crash, or something else). You may also want to implement some kind of lock reackquire for the same user - when user opened the page for the first time, then closed it without saving data and opened once again - he should be able to edit the data. This can be done by identifying user somehow - login, cookie, and so on.
I would like to make a call from one of the Smartsheet Column Cell to a Java code running on web server (could be Servlet or a Portlet).
The Java code will retrieve other relevant data from a data source (database) and updates the resultset information retrieved from data source into other column cells in the Smartsheet.
One immediate solution I could think of:
- Create a hyperlink pointing to Java code and add it to one of the desired Cell.
- If the user click on the hyperlink in column cell then trigger the call to Java code and update the rest of columns (for that particular row).
I would like to know if there are other alternatives/ideas of doing it ?
Your solution of providing a hyperlink in a cell to trigger an external script that will populate the rest of the cells in the row sounds like a viable solution.
Depending on the level of interaction you're looking for in the process, there is also the Data Tracker project. Data Tracker is a Python app that runs in the command-line that uses a value in the row to find corresponding data in external systems. The app can be configured to query several different types of data sources, and can even be extended to include other data sources that meet your needs.
This would be more of a scheduled solution, rather than an interactive solution with the user clicking the link.
I am generating a table depending on the user's selected choice by calling a servlet using AJAX call onchange of dropdown. The table is generating fine, but the problem is I want to page the table as well as it has a lot of rows. I have tried a lot of jquery plugins, but haven't been able to page the table as most plugins want table id which is only generated on ajax call.Please Help...!
Simply call the paging plugin in the success callback for the AJAX request, since at that point the table will exist and you should know the id of the table. If you don't know the id of the table at that point the easiest solution would be to modify the server-side code to pass that back as part of the response (as a property of a JSON object).
If that's not an option then you'll have to traverse the DOM in order to get a reference to the table, then get the id from that. I'd need to know the HTML structure of the page to tell you exactly how that would look.
You can use the this plugin
http://tablesorter.com/docs/
You can trigger the sorting externally by refering this url
http://tablesorter.com/docs/example-trigger-sort.html
I'm using Spring Roo, and Spring MVC.
I have Set up Spring Security to use a MySQL database and auth using the standard schema, table users, table authority.
What I have is a webapp to take orders from our sales people in the field. Simply they just fill in the form and submit it to the database.
The ROO generated MVC pages are fine to start, but I need to make some changes and I'm not sure exactly how to do it. I'm just getting my feet wet learning java.
What I need is for our sales order form to capture the username, and the submitted record would be tagged with their username, and then filter the view so that the sales person can only see the records that they themselves have submitted.
Also I would like to implement a stylus signature capture at the bottom of the form. I tried to figure out how to use http://thomasjbradley.ca/lab/signature-pad/#howto but I'm getting lost on where to put the code. I assume in src\main\views\salesorders\create.jspx
I understand this part is off-topic to my original post.
You will need a table in your database that holds the order forms. An important part of this table will be each row will need to contain a way to map back to the user that submitted it. This will most likely be easiest to implement with a column that is a foreign key to the user table.
When it comes time to fetch for forms for a specific user, you will need to query the order forms table and use a WHERE clause that restricts the rows to just the current user.
As for your second question, it will likely be more worthwhile for you to ask in another question on stackoverflow, as it doesn't really pertain to the original question at all.
I am working in Spring MVC 2, Jsp, Dojo, Javascript.
Actually I am populating Jsp page table-grid with list of objects coming in form command object. Let say 3 records displayed in grid. I am deleting third record with JavaScript getElementById.. delete-row/removeChild functions. That record is deleted from presentation i.e. grid. Now when I save this. It takes 3 records to server side instead of 2. It should take 2 records because the third record was deleted. I am using Dojo to dragNdrop grid rows.
If you're using a grid component that maintains a datastore - e.g. the DojoX DataGrid, you might be removing the markup for the row, but not telling the datastore to purge the row data. When the save occurs, the datastore sends all three rows.
If you are using the DataGrid, you should delete the row from the DataStore, which will be reflected automatically in the UI.
When I have this kind of issue, I always check the cache related headers in my response.
Could it be that the http request supposed to fetch saved data from the server in order to refresh the view doesn't hit the server, but instead hit the browser cache?
Could not resolve issue but another logic fulfills my need. Spring form tags were used to bind this for with objectclass. Converting deleted item row's id to negative and hiding this row at client side does the trick. When form submits this negative id converted to positive value and deleted from DB.