Are two different instances merging? - oracle-adf

I am having a form which is used to either create/ edit new Departments. I have a functional requirement to unhide few fields after few fields are filled with data.
When I open two Departments to edit, one department has the first set of fields unfilled and hence it hides the second set of fields.
In the second Department which has first set of fields filled, I can see (visible) the second set of fields (which is the way it is coded). But now if I go back to the first Department(already opened in another tab)(open the tab, we coded to refresh the tab on focus), which initially was not filled with the required details, I see that the second set of fields are enabled (of course the filed are yet unfilled).
I am sure that they have different transactions and also different instances but unable to understand this behavior, any idea on how to debug this?

If you are using the same VO for the same AM/DC then yes, they are sharing the same data (VO Rowset and Binding integrator) so changes to one will be reflected dint he other.
If I understand your problem correctly, one solution would be to create separate Task Flows, one for each Page and then convert the Bounded taksflows with page fragments. and here. Then drop these task flows (as Regions) onto the respective tables. Make sure to mark the task flow as Always Use New Transaction and here and Data Control Scope/Frame as Isolated and here. If the two task flows need to communicate with each other use a contextual event here and here.

Related

AS3 / Animate CC: user can edit table contents

This question relates to strategy rather than specific code. I'm struggling to think of a viable approach and I'm hoping somebody may have encountered a similar challenge.
I'm building an Animate program that will:
Enable the user to draw a line on the stage (by means of a series of mouse clicks).
Capture the coordinates of each mouse click in an array, and add them to a table that is displayed and updated in the UI.
Display the resulting line.
Enable the user to edit any of the coordinates, and update all of (1) (2) and (3) accordingly.
The first three steps are working OK, but darn ... how should I make that data editable? I've put a listener on the textfield that holds the set of coordinates, but I think that's a dead end. It's just a string with line breaks, so it would be hard to edit a particular few characters and have AS3 / Animate detect what had changed.
Is there a good technique for this?
Background: was comfortable with AS1, skipped AS2 completely, and now (12 years later), I'm grappling with AS3. It's been frustrating, but ... I've built a package and it's working.
The most important concept you need is the Model-View-Controller design pattern.
model
Start with defining your model which represents the data in your application.
Do so according to your requirements.
The minimum requirement for an object to work as the model is that it notifies others when it got changed, because MVC is based heavily on the observer pattern and you want to observe when your data changes. In As3, using the built in EventDispatcher makes sense.
In your case, a nested model makes sense, that is, you have a model for each individual point and then another model that acts as a collection of all points.
Add methods to your model classes to modify the data. You want to add and remove points to the collection of points and you want to modify the coordinates of each individual point.
view
Each view receives a reference to the model object that represents the collection of points. One view might draw them into a coordinate system and connect them with lines, another might be a tabular representation.
controller
The controller knows about the model and reacts to user input on the view.
For example, when somebody clicks on the view, a new point is inserted.
Given the simplicity of your application, it might makes sense to combine view and controller, so that each view directly manipulates the model.
how should I make that data editable?
By creating methods on the model that allow you to do exactly that.
Say for example the LineView class receives the PointListModel which includes all points and stores it in a private variable
public LineView (pointList:PointListModel)
{
list = pointList;
Now it will create graphical assets to represent the points, based on the list (this should be executed whenever the PointListModel object signals a change:
private onListChanged(event:Event):void
{
for each(var point:PointModel in list)
{
// draw circle or whatever
As the creation of each visual asset in the view is based on the model, it should be possible to connect them. When the user now modifies the visual asset, the made modifications can be applied to the PointModel object. Remember: any modifications made to a model will cause it to dispatch an event that it was modified. This will inform all other views that this point was modified.
This is how dragging & dropping the circle representing a point in one view will make the coordinates of that point displayed in another view update as if they are linked together, because they are: via the shared model object.
I am still a bit hazy about how I would associate the displayed table with underlying array data. Should I make each row of the table a separate textfield with an associated listener?
This is up to you.
You could make the entire table only listen to the change event of the model that represents all points. This would cause the entire table to be updated.
Or you could make the table observe the point list model to add or remove table entries and each entry in the table observe a point in that list. This allows you to only update a single entry in the table if only one point got updated.
Keep in mind that the components of flash do a lot of this for you. Flex has even more sophisticated components. The way each entry is rendered can be defined with a custom itemrenderer.

Persisting and rejecting changes to different levels of a hierarchical association - Extjs 5/Sencha

I'm facing a very critical issue where I can't persist my data to the server.
I am building a dashboard where the user can create new dashboards and customize existing ones. A dashboard layout will have one or more rows. Each row contains one or more cells which vary in width. Each cell will have one or more widget instances where it holds a reference to a particular widget. So you have data about widgets in another table. And I'm using table storage.
So I have the tables as follow.
Page, PageLayout, Row, Cell, CellWidgetInstance
Widget, WidgetInstance
So I have models for all the above tables and added a store for getting a particular page layout.
Page HasMany PageLayout
PageLayout HasMany Row
Row HasMany Cell
Cell HasMany CellWidgetInstance
CellWidgetInstance HasOne WidgetInstance
WidgetInstance HasOne Widget
So I can build the entire view or the edit view modes of the page using the pageLayout returned from the store. So I can access to the Rows collection and go on to the lower levels.
Now the problem comes when I'm trying to save the changes. In the edit view user can add/remove rows, add/remove/update cells, add/remove WidgetInstances etc.
And if the user wishes to click cancel after doing all these changes it should not go to the server and I should be able to reject all the changes in different levels. And if the user wishes to save I should be able to save all the changes in one transaction.
I hoped by adding all the necessary CUD (create/update/delete) proxies to the models, doing pageLayoutStore.sync() and pageLayoutStore.rejectChanges() would do the trick calling each model's create/update/delete urls as per the changes. But it seems although sencha supports retrieving the whole hierarchy it does not support saving as a hierarchy still.
So I'm now hitting a major blocker where I can implement the functionality I needed which is a very standard functionality in most cases. Saving/rejecting models and associated models.
I spent hours searching the web and the sencha forums and all they say is sencha still does not support saving associated data. And in one case there was a work around to save the models then and there without using the store. But in my case I can't do this as the user might cancel after editing.
Can anybody suggest a work around for this?
Many Thanks,
Dushan
You're absolutely right - Sencha does not support saving a nested document.
There are a few workarounds. The simplest one is to use the 'auto' type, at the top level, and give up the power of models the rest of the way down.
A slightly more complex version is to use a custom writer to your PageLayout class, so that it can construct the data to be sent by hand; this will give you full control, and allow you to save your models at the PageLayout level.
It's also possible to extend Model to allow for additional association types - I've done this for my current project, but it's somewhat complex (and, no, I'm not in a position to share it at this time). If you've only got one "top-level model" to save in this nested fashion, then the custom writer is the easiest.

How to quickly populate a combobox with database data (VCL)

I have read all sorts of documents across the web about what should be a farly common and painless implementation. Since I have found no consistent and slick reply (even the Embarcadero website describes some properties wrong!) I am going to post a "short" howto.
Typical, frequent use case: the developer just wants to painlessy show a couple of database-extracted information in a combo box (i.e. a language selection), get the user's choice out of it and that's it.
Requirements:
Delphi, more or less any version. VCL is covered.
A database table. Let's assume a simple table with an id and value fields.
A DataSet (including queries and ClientDataSets).
A DataSource linked to the DataSet.
A TDBLookupComboBox linked to the DataSource that shall show a list of values and "return" the currently selected id.
Firstly, we decide whether the sort order is the one we want or not and if all the items in that table must be shown. Most often, a simple ORDER BY clause or a DataSet index will be enough. In case it's not, we may add a sort_order field and fill it with integers representing our custom sort order. In case we want to show just some items, we add a visible or enabled field and use it in our SQL. Example:
SELECT id, value
FROM my_database_table
WHERE visible = 1
ORDER BY sort_order
I have defined visible as INTEGER and checking it against 1 and not TRUE because many databases (including the most used SQLite) have little support for booleans.
Then an optional but surprisingly often nice idea: temporarily add a TDBGrid on the form, link it to the same TDataSource of the TLookupComboBox and check that you actually see the wanted data populate it. In fact it's easy to typo something in a query (assuming you are using a SQL DataSet) and get no data and then you are left wondering why the TDBLookupComboBox won't fill in.
Once seen the data correctly show up, remove the grid.
Another sensible idea is to use ClientDataSets for these kinds of implementations: due to how they work, they will "cache" the few rows contained in your look ups at program startup and then no further database access (and slowdown and traffic) will be required.
Now open the TDBLookupComboBox properties and fill in only the following ones:
ListSource (and not DataSource): set it to the TDataSource connected to the DataSet you want to show values of.
ListField: set it to the field name that you want the user to see. In our demo's case it'd be the value field.
KeyField: set it to the field name whose value you want the program to return you. In our demo it'd be the id field.
Don't forget to check the TabOrder property, there are still people who love navigating through the controls by pressing the TAB key and nothing is more annoying than seeing the selection hopping around randomly as your ComboBox was placed last on the form despite graphically showing second!
If all you need is to show a form and read the TDBLookupComboBox selected value when the user presses a button, you are pretty much sorted.
All you'll have to do in the button's OnClick event handler will be to read the combo box value with this code:
SelectedId := MyCombo.KeyValue;
Where SelectedId is any variable where to store the returned value and MyCombo of course is the name of your TDBLookupComboBox. Notice how KeyValue will not contain the text the user sees onscreen but the value of the id field we specified in KeyField. So, if our user selected database row was:
id= 5
value= 'MyText'
MyCombo.KeyValue shall contain 5.
But what if you need to dynamically update stuff on the form, depending un the combo box user selection? There's no OnChange event available for our TDBLookupComboBox! Therefore, if you need to dynamically update stuff around basing on the combo box choices, you apparently cannot. You may try the various "OnExit" etc. events but all of them have serious drawbacks or side effects.
One possible solution is to create a new component inheriting from TDBLookupComboBox whose only task is to make public the hidden OnChange event. But that's overkill, isn't it?
There's another way: go to the DataSet your TDBLookupComboBox is tied to (through a DataSource). Open its events and double click on its OnAfterScroll event.
In there you may simulate an OnChange event pretty well.
For the sake of demonstration, add one integer variable and a TEdit box to the form and call them: SelectedId and EditValue.
procedure TMyForm.MyDataSetAfterScroll(DataSet: TDataSet);
var
SelectedId : integer;
begin
SelectedId := MyDataSet.FieldByName('id').AsInteger;
EditValue.Text := MyDataSet.FieldByName('value').AsString;
end;
That's it: you may replace those two demo lines with your own procedure calls and whatever else you might need to dynamically update your form basing on the user's choices in your combo box.
A little warning: using the DataSet OnAfterScroll has one drawback as well: the event is called more often than you'd think. In example, it may be called when the dataset is opened but also be called more than once during records navigation. Therefore your code must deal with being called more frequently than needed.
At this point you might rub your hands and think your job is done!
Not at all! Just create a short demo application implementing all the above and you'll notice it lacks of an important finishing touch: when it starts, the combo box has an annoying "blank" default choice. That is, even if your database holds say 4 choices, the form with show an empty combo box selected value at first.
How to make one of your choices automatically appear "pre-selected" in the combo box as you and your users expect to?
Simple!
Just assign a value to the KeyValue property we already described above.
That is, on the OnFormCreate or other suitable event, just hard-code a choice like in example:
MyCombo.KeyValue := DefaultId;
For example, by using the sample database row posted above, you'd write:
MyCombo.KeyValue := 5;
and the combo box will display: "MyText" as pre-selected option when the user opens its form.
Of course you may prefer more elegant and involved ways to set a default key than hard-coding its default value. In example you might want to show the first alphabetically ordered textual description contained in your database table or whatever other criterium. But the basic mechanic is the one shown above: obtain the key / id value in any manner you want and then assign it to the KeyValue property.
Thank your for reading this HowTo till the end!

How to provide Prompt Lists in an NHibernate WinForms application

Background
WinForms application using NHibernate. Application is in MDI style and each MDI child form opens a new NHibernate session at Load which remains open for the life of the form.
Question
My application is basically an "order management" or "purchasing" system. One particular form uses a lot of "lookup" lists. Like a list of products, a list of vendors, a list of locations, a list of UnitsOfMeasurement, a list of PriceQuotes, etc.
Lots of lists, that all get loaded when the form is constructed.
Problem: I need the lookup lists, but I need the form to be a bit faster to load. The form is taking too long to perform all the lookups. How can I get better performance and keep my lookup lists?
My Thoughts
Can I load the lookup lists once and hold on to them for the life of the application, and periodically check to see if the lists are stale?
Can I load just the text description for the lists, and instead of holding a bunch of IList, IList, etc, I could hold a bunch of IList, and then when I save, perform the Gets against NHibernate to get the real object.
Is there some other approach that I just haven't thought of?
You should definitely cache slowly changing data to improve performance. How often you need to check for stale data depends on the type of data and your business, e.g. units of measure probably doesn't change as frequently as a list of products. You should also provide a method for manually refreshing lists so that the user can refresh them if something appears to be missing.
If you need the business objects in the list in order to perform a database operation, you can call ISession.Lock(obj) to lock the object into the current ISession. One thing to be aware of is that the lock doesn't automatically cascade to child objects: I think there's a mapping setting to do that or you can do it manually.
Are you sending lists of full objects to your UI? I recently worked on an app using DTO's between the data layer and the UI so I'm not sending the full object, just a description and an identifier. That could help you trim out some unneeded data. So basically when the screen loads a service call is made, nhibernate gets all of the objects I want for my list box, then the UI binds to the list. I bound my listbox display member to the description and the value member to the identifier.

Delete Records from Access database, error while deleting

I have the following situation: I built an Access form with a subform (which records are linked to the records of main form via certain key). When I try to delete any record in the subform, I get the following message: “Access has suspended the action because you and another user tried to change the data” (approximate translation from German). Does anyone know how to delete those records from the subform (and, respectively, from the table behind the form).
If you are currently 'editing' the current form then it will not allow the action. Editing a record can sometimes be triggered by simply clicking inside a field, or other simple actions you wouldn't normally consider 'editing'.
This is usually avoided in Access by using the RunCommand method to undo any edits before deleting the record:
DoCmd.RunCommand acCmdUndo
samjudson suggested:
DoCmd.RunCommand acCmdUndo
You can also use Me.Undo, to undo the last edit to the form in which the code runs.
Or, Me!MySubForm.Form.Undo to undo the last unsaved edit in the subform whose subform control is named "MySubForm".
You can also use Me!MyControl.Undo to cancel the last edit to a particular control.
"DoCmd.RunCommand acCmdUndo" will apply the Undo operation to the currently selected object, but you won't know for sure whether it will apply at the control or form level. Using the commands I suggested completely disambiguates what gets undone.
Keep in mind, though, that Undo will not undo edits to a control after the control's AfterUpdate event has fired, or to a form after its AfterUpdate event has fired (i.e., the data has been saved to the underlying data table).
Also check the "row locking mechanism" that you have. I haven't used Access in a while but I remember that you could use set that in the table properties. You can access those properties clicking in the famous "dot" in the upper left corner of the table to bring up its properties. Well if you're using Access, you know what I'm talking about.

Resources