I am trying to dynamically reflect the changes of the data to all logged in users' screens.
There are items being added to the database or one of their attributes is being changed by users or by scheduled tasks(cron-jobs).
What I want to do is reflecting those changes to all logged-in users' screens without a need of page refresh. This includes certain parts of all screens. One part is left menu side of all screens, the other one is table contents.
I am able to do that for one logged-in user via re assigning the changed datasource to the table and re building the left-side menu after re-assignment of the datasource. But this is only for the current user. I need to change all user screens which are currently in use at that moment.
I have checked Vaadin PUSH but could not really relate to it.
How can I do that with Vaadin?
Thank you in advance.
Check this out:
https://vaadin.com/docs/v8/framework/articles/BroadcastingMessagesToOtherUsers.html
In short, you can use the Observer Pattern to notify all the UIs about changes in the database. You also need to enable push and modify the UI using the UI.access(Runnable) method.
Related
I am working on a Swing GUI, which consists of several panels, tables and table models which are connected to an underlying MySQL database using Hibernate.
My current aim is to store information about the current user, id and table name, in a kind of History/Log table.
The problem I'm facing is that I have to pass the user name to all panels to the table model, because this last one is the responsible to create a new log record in case of UPDATE, SAVE, DELETE events.
I am thinking about a way to separate user variable from panels/table models.
This at least would spare the pass-through of user variable through panels.
Any ideas or suggestions?
As stated in the answer to this question: Get currently logged in user from controller in java swing, using Singleton pattern is an elegant solution to keep current user's data "global" and accessible in the entire life-cycle of your application, from user's log-in until user's log-out.
See an example of implementation in this answer.
Problem:
Whenever we save the data of two different records in two different tabs of the browser for the same session, data is getting mixed up for the respective saved records.
Scenario:
1) Tab1: Open the browser and login to the application and go the search screen. (In our case Guarantor search screen).
2) Tab2: Open another browser tab in the same browser, copy the URL of the previous step and paste it into the current tab, now search screen opened in both the tab.
3) Go back to Tab1 and search for one guarantor (for ex: Guarantor with some number like 34526) and open it once after getting the result in the search screen.
4) Then go to Tab2 and search for another Guarantor record and open the same.
5) Now Click on Edit button for editing the record opened in Tab2 and then go back to Tab1 without editing the data in Tab2.
6) Now Click on Edit button for editing the record opened in Tab1 and then make the modifications and do some action in this screen like 'SAVE' operation, at the same time Go to Tab2 and click on 'SAVE' operation on this screen also. Now Here we clicked the save button on Tab1 and in the mean time before Tab1 completes its save operation we did another action (i.e. SAVE) in Tab2 also.
7) Now data got mixed up for both the screens at this time (which is not a correct behavior). In this case data shouldn't be mixed up, it should be saved properly for the corresponding record.
Please note that in the above scenario opened screen will be same for both the tabs but with Different record. (For example: Opened the screen for 'Edit Guarantor' but with two different Guarantor records).
Preferred Solution By Client:
Application should allow to make the changes for the records opened in multiple tabs without breaking the application flow. The user logged into the application will be same in the case and application should allow multi-tabbing feature without mixing up of the data.
Possible Root causes for the issue are:
1) Browser version from IE 7 and above maintains single session throughout the browser, even if you open new window also it will be having the same session.
Since we are using IE8, it maintains single session even through different Tabs also. Which might be creating this problem.
We did some research on the above issue and also checked with some blogs but we are not able to trace the correct solution for our problem.
We checked few things to solve this issue like:
1) SessionStorage concept which is available from HTML5 and can support from IE8+ browsers but this solution won't support our requirement which we mentioned above. If anybody got the above results with the help of this please let us know.
2) We found another solution: URL re-writing - (appending the session details nd some unique details to distinguish the session and maintain some hidden fields to keep track of the session in each and every page) - But this is very complex and also we are not sure whether this solve the above said problem. Please let us know if any suggestions in this regard.
We also tried some examples with some JavaScript coding but didn't get required solution with them.
We are expecting some guidance or similar solution if somebody already implemented in their application.
Did you try setting the scope of your form bean to request? By default, struts's form bean is session scoped. So the bean that you are posting back to the server is shared between the tabs. If you set the scope to request, then you will have different form beans in different tabs. This will ensure that when the user hits save, data is not mixed up.
I have seen this issue with couple of struts applications which asks users to fill the data on multiple pages (users fills data on one page, clicks next ...reaches till last page and click on save and then the data is saved in the database). When user clicks on next to go to the next page, the current page (form) data is saved in the HttpSession (Struts automatically does that, if the bean scope is session). When the user opens the application in multiple tabs or browser windows (assuming user is using same browser (e.g. IE) for multiple windows) and acting on forms for different records, data gets saved/overwritten in the same session and gets corrupted. Your case is also similar.
As you rightly pointed out the jsessionID is little bit complex to implement because if you are rendering some links (links pointing to other part of the application from an xml file) on your web page, you need to embed the jsessionID in the URL otherwise server will assign a new jsessionID and will redirect the user to the login page (assuming your enterprise application asks the user to login first)( Dynamically generated link will have the jsessionID already embedded with them). Second problem with this approach is : if user right clicks on any link (assuming jsessionID is embedded in it) and select open in a new window/tab and then navigate to some other record to edit it, your data will get corrupted (Please note that when user selects open in new tab for a link, the URL for that link will already have the same jsessionID from the parent window/tab).
To solve the issue, you will have to make some design changes in your application. Below is the possible approach.
Rather than storing the data in HttpSession, you can store the data in a cache ( you can have your own logic to store data as key value pair, explained below ). I guess you will have to follow below steps:
a) Change the bean scope to request from the session.
b) Have a unique identifier for each window/tab. You can use windows.name property for the same. This property is supported by all the major browsers. You should send this tab/window name to the server each time you click on next/previous/save.
c) At server side to store the data, below approach can be followed (May not be the best one, feel free to tune it. :-) )
HashMap -> key will be the jessionID and value will be another HashMap.
- HashMap(value of the first Map) -> key will be tab/windows name sent from the browser. Value will be another HashMap.
- HashMap (value of the second map) -> Key will be form name. Value will be the actual form. (this map will have only one entry, if you have only one form).
d) Once you approach on the last page, get all the forms from the Map for the desired tab/window and save in the database.
For point (c) mentioned above, you can use the database to store the intermediate data. Both the approaches have pros and cons.
i) Storing/retrieving data in/from Map/Data Structure is faster compared to the database.
ii) Storing data in data structure consumes space on the heap. However as of now you store data in the session so that should not be an issue.
iii) Data gets lost in case of server crash, if stored in the DS. From the database data can be retrieved back.
I am creating an android application and i need to manage how to display data of list view in some fragment .. My list view consists of multiple sections with a header on each section.. The data of these sections are loaded from a web service(web call for each section) and i need to manage which sections to display to the user and also sort the sections by priority so that the important sections are displayed at the top of the view.
My question is how can i make this configurable and loaded once in my application so that when getting the data i can construct the list view properly using an already loaded configuration, i thought of using SharedPreferences or maybe an XML file as a configuration storage.
Again, my interests are to:
Manage which sections to be viewed in my list view. (for all users and not per user)
Sort the sections by priorities.
Thanks in advance for the help.
I believe you should have a database and store the settings for each user there. Based on data stored in the database you can generate XML, if needed. This would be very useful, as if you open the application with another android phone, but log in with your user, your settings would be loaded as well.
In my play app I'm trying to offer the user the oppotunity to edit a specific item he selects from a table by clicking on a button in the same table row as the item.
To be more precise the user will edit the students that have enrolled for an exam. After clicking on the exam he wants to edit a modal will open. Inside the modal a table will show all available students with a checked checkbox for students which are already enrolled.
My only problem is: How do I pass the modal the id of the exam the user wants to edit? As far as I've researched I cant't define and edit variables inside of the template. In Angular I would just modify a variable in the scope.
What is the correct way to do this?
The general principle of moving initialization data from the back-end to the front-end is to inject it into the markup someplace, using the templating engine. In your case, in whatever loop you're using in your template to render the table rows, you simply drop the ID in it's own cell in the table, in a class or id attribute, or maybe most appropriately, in a data- attribute on the table row. I would say each of these options is pretty much equivalent, mostly differing aesthetically.
Then, in your click handler, you just use a relative selector on the event target to pull the ID into your script, wherever you stashed it.
The other approach is to render your table on the front-end, pulling this information from the back-end via API, in the style of a single-page app. Then, that association between ID and data lives in the model before its even rendered. This may be overkill for this one example, but if you've got rich interactivity with a dozen of these sorts of screens, I think this is a much more scalable approach.
Say you retrieve 100 records, and display them on a page. The user only updates 2 of the records on the page. Now you want to update only the two records, and not the other 98.
Is it best to have one submit on the page, then somehow know which 2 are updated, then send only those two to the db for an update?
What does the "somehow" look like?
Or, would you have an update-submit button for each row, and have it only update the record its tied to?
Of course there are different ways you could do this. In general, you can save yourself some trouble and server-side processing by using Javascript to assemble your POST data for only the records that have changed. Two thoughts on how this might work:
1) Go the ajax route and do live-editing. So records are presented in a table and appear to be non-editable. When a user clicks a particular row, that row becomes editable by using Javascript to create the appropriate html form on the fly. Then have either a submit button or some other handler (say, moving focus to another table row) which will trigger the POST which updates the DB (asynchronously via your preferred ajax method). Happily the mainstream Javascript frameworks can help a lot in this area.
2) Checkboxes - whenever a row is edited, its checkbox becomes checked. When the submit button is clicked, use javascript to post the POST data by grabbing everything in row whose checkbox is checked. A user can un-check a box to cancel changes to that row before submitting.
Ajax it using jQuery or some other JavaScript library and put and update button on each row.
There are many answers to this question and to some extent they depend upon your development tools and the "feel" of the site.
If you were implementing Ajax calls to do the updates on a line by line basis then this would logically seem right to have a button per line and then update it with an Ajax call when a line was changed.
This is also just the scenario that disconnected data sets were designed to solve and ADO.net handles these very well.
So as ever, the answer is "It Depends!"
You can use JavaScript to mark each field as changed when a user changes an input field. Create a hidden fields that has the id of the row you are updating, and dirty flag. (like is_dirty_$id) In JavaScript, create an onChange handler that sets the hidden field as dirty. when any input is changed.
Alternatively, you can create hidden fields for each real field you display. the hidden field would contain the initial values. check each field on the server side to determine what has changed.
You probably want to store a last_modified date as a hidden field for each record. This way if another user updates the same record, you can display an error message saying "this record has been updated by another user" or similar.
One submit button. I could foresee case I might use more then one, but in the general case just one. (Note, this looks like a web page question to me, so I'm answering with that assumption.)
There are 3 ways that come to mind which you could handle the tracking changes:
JavaScript: Put a onChange() function on the controls that update a hidden field. If that hidden has a value, then update the associated record. Requires JS on the browser, and doesn't tell you which fields to update, just which records.
Lots of form fields: Put a hidden field out with each control and compare them all when they come back. This would be ugly, but it would allow you to know which fields to update (not just the record). It would also allow you to know if someone undid a change that started.
Sessions: You could place the original values in session variables, then do the comparison when the values come back. This would be a little more elegant then lots of hidden fields, and less open to people playing with the posted back data (since you should never trust anything that comes back, even in hidden fields). Requires cookies on the browser and sessions on the server technology.