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.
Related
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.
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.
I have an employee and a corresponding employee history table.
Both the tables have same structure. History table is used to track the historical changes made to the employee over a period of time.
Now, I need to add an undo function to the changes made to the employee.
e.g. Employees title is changed on 1st August. Now, This will update the employees title in Employee table and insert an corresponding history record in employee_history table.
Now, I need to undo this change. Employee edit page will have a list of changes made to employee datewise with an undo button beside it.
Clicking on undo should revert changes in Employee table to previous value. Also I think the record in history table which says title is changed, should also be removed.
Also when I revert tghe changes to employee table i.e. revert title to previous title, this will fire an insert to history table, which I dont want.
I am not sure what is the best possible way to do this.
Any suggestions will be helpful.
In case you want to implement a "persistent" undo - one that would survive an application restart/session timeout, you should consider extending your DB schema width timestamp fields and either delete the last entry or replace it with an appropriate earlier entry.
A "light" version would be using a stack to store last interactions, including the original and the new value. You could persist the stack on session invalidation of course to combine both approaches. This seems to be what you are actually doing.
You could extend this solution by creating and storing or exporting SQL migration scripts for each change, recording the change and, if possible, the opposite action. So you could even transfer the scripts between application instances and environments and would have a complete "replayability" of your DB states.
tl;dr - it looks like you have already implemented a good solution
I would suggest using a flag telling the trigger/history logic to keep off while you have your undo running and not writing history data.
Normally this would be done by serializer-class feeding from your history table and restoring employee data and later cleaning up history-entries/unlocking history again.
You could maybe use the rollback feature of the transaction.
So I'm creating a program that auto generates forms for data entry. The form is created by a user (its a simple table setup with the ability to merge cells). Some of the cells contain text views, others contain text inputs (all based on how the user draws it).
This form is then sent to another application that draws it back out. I was wondering what the best method is to represent the form. I though either use XML to represent the form or use a database that would basically function as a grid and row 1 column 1 in the database would match the form cell row 1 column 1 and so on (kind of an odd way to use a database).
The form creation program is made in C++ and the form regeneration program is created in Java.
Is there an even better way to do this?
Thanks,
I am also thinking the same thing because I am in to creating dynamic forms for my framework to. So I will share some thoughts with you. Using database to add new forms like adding a record in one table that specifies the form and its fields in another having the ability to select it's field types to, or creating one table for each form and each time create a new table or altering its fields (sound messy).. or create a folder with a bunch of xmls that are used for the structure of your forms?
When it comes to database:
Your application is stricted with a specific database application
like sql server 2008 or mysql or mysqli or oracle etc.
Your application is causing network traffic, not that bad but it is
doing it eveytime you need to create or use a form.
You need a panel that creates those forms using the database, and
can be accessed if its web even from your mobile.
When it comes to XML:
Your application is free from database version restrictions.
you need the impersonator to have the right to create files in a
spesific directory in your frameowork.
You don't need a panel even though you can create one, because XML are human readable files. So you can make one while eating your dinner and serve it to your system,
and wala, you have your form generated.
These are my thoughts for now.
How about the methods that will be used in the form? will those also be dynamic? How can you specify what calls what? this is also what you need to take in account.
I think that XML is a much better choice here. Using database as a grid could be more of a headache than needed. You will have to deal with all the problems related to having the database and not really get any benefits of the database. The industry decides to go with xml more often than not as well (xbrl being one example).
I am building a product in which customers can create dynamic form depending upon their requirements. For example one customer can create a form having fields like first name, last name, others can have one extra field like middle name.
I want to store each and every customers settings and finally i want to merge these two settings into one form at the time of display to our end users. I am finding right way to implement it.
Finding a way to store individual customers settings either in Database or XML or anything.
Finding a way to merge customers settings into one form, once our end user select both customers to apply (i want to give only one form which contains both customer form fields).
Please remember that i am providing a tool where customer can create new label like Gender, which is not defined in the system. We are giving generin data type to create such fields using text box, text-area, table, check-box, radio and many more.
Please assist me to design the architecture of above problem set.
You can do this by modelling your database as Entity–attribute–value model. See this :
Using Database Metadata and its Semantics to Generate Automatic and Dynamic Web Entry Forms
Planning and Implementing a Metadata-Driven Digital Repository
You can also find useful threads here in SO in the tag: eav