I am using a Vaadin Grid with buffered editing. I am adding an item to it as such:
items.add(hashMap);
dataProvider.refreshAll();
Then I attempt to edit the entry. I have these two editing buttons:
Button cancelButton = new Button(VaadinIcon.CLOSE.create(),
e -> editor.cancel());
Button saveButton = new Button(VaadinIcon.THUMBS_UP.create(),
e -> editor.save());
I also have saveListener which does the following:
dataProvider.refreshAll();
Without it, the grid does not update.
Anyhow. Here is the issue. If I edit, and I do not write any new data, the cancel and save button works the same. And I can re-edit. All is good.
However, when I edit and write any new data. I can save, but I cannot re-edit the entry I just saved.
If I add a new entry, I can now re-edit the entry that was locked before.
It is as if that entry is not part of the grid or the dataprovider because my addSelectionListener also does not react when I select that entry. Yet, I do find it in my item-list.
Furthermore, if I add a system.out to the editing component listener, nothing is shown in the log.
So what am I missing?
You serm to use Hashmap as data object instead of a POJO. That will require you to add unique "id" property to your map and override DataProvider to use it as an identity. See full code example here: https://cookbook.vaadin.com/grid-with-map
Related
This question already has answers here:
Add a New Item to a Table / List
(2 answers)
Closed 17 days ago.
We have to perform edit functionality where we have to take two scenarios into consideration:
Make changes in existing entries.
Add new entries and update the old entries.
In the 2nd scenario, when we are trying to add a new entry, it is getting added to sap.m.Table but if we make any change in the old entry then the newly added line item is disappearing.
let oContextLineItemEntry = oLineItmTab.getModel().createEntry("/EntityName", {
properties: NewLineItem,
});
let oTmp = oLineItmTab.getBindingInfo("items").template,
oItem = oTmp.clone();
oItem.setBindingContext(oContextLineItemEntry);
oLineItmTab.addItem(oItem);
Here NewLineItem is an object which I want to add and it is blank. It is initiated like below:
NewLineItem = oLineItmTab.getItems()[0].getBindingContext().getObject();
After this, I have removed all the values of the objects attribute.
I tried with OData V2 OneWay binding, but it didn't work.
I saw framework behavior is triggering this interaction
onChange started
onChange completed
I went through these questions on SAP Community:
https://answers.sap.com/questions/699607/newly-added-table-row-disappearing-when-changing-p.html
https://answers.sap.com/questions/13305104/ui5-controls-and-onchange-event-in-a-sapuitabletab.html
After you bind an aggregation it will be managed by the data binding. Therefore you should not try to modify the aggregations. Instead, do the changes in the model and then the aggregation should be updated according to data in the model. e.g.
let newRow = {key: "_your_unique_id_", value: ""};
let model = table.getModel();
let tableData = model.getProperty("/tableEntityName");
tableData.unshift(newRow);
model.setProperty("/tableEntityName", tableData);
Besides that consider to set the growing property of the table to true.
We had raised an OSS note for this issue to which SAP replied, this is not and issue with UI control but the way to use it.
Basically we are not supposed to add new entries when OData binding is being used.
I have seen there is a problem refreshing only current row if the data are changed in another form (and DataSet too) or even if the data are changed on server side (in trigger or from another user).
So i find solution that partially work with DevExpress's cxGrid and have following issue.
frm:=TfrmEdb01.Create(Self); // create edit-form
try
frm.LoadData(0); // do the insert in TAdQuery
frm.ShowModal; // Show edit form
// after closing an Edit-Form, make a new record in cxGrid
row:=tv01.dataController.InsertRecord(tv01.Controller.FocusedRecordIndex);
// for each column in grid...
for col:=0 to tv01.DataController.ItemCount-1 do
begin
// ...get its FieldName
sFld:=tv01.DataController.GetItemFieldName(col);
// and if this field exist in edit-form's Query
if frm.q01.FindField(sFld)<>nil then
//then assign this value to the newly created row in the grid.
tv01.DataController.Values[row,col]:=frm.q01.FieldByName(sFld).Value;
end;
finally
frm.Free;
end;
And realy, when I step out from the edit-form there is a New row created in the cxGrid. Problem is in that:
- if is double-clicked (to open edit-form again) then the previous record is opened. It seems to me the Data acctualy did not updated in Query object, only in GridView... maybe I should use values from Grid instead of Query object.
- if select another record (scroll them up and down), and then want to select again this new record, then it can not be focused at all. Only if I reload whole dataSet, then this new record can be selected same as any other.
Cheers!
p.s. To clearify a problem, I will provide whole test-project. There is also SQL script to create a table in the database, and AnyDac connection must be set to Your database.
There is also an image thate will/should ilustrate a problem.
You have call post to save the changes to the underlying dataset. Do it just before finally.
tv01.DataController.Post();
See the help for TcxCustomDataController.Post for more details.
In one form I have system OK button :
#Order(910.0)
public class SaveButton extends AbstractOkButton {
#Override
protected String getConfiguredLabel() {
return TEXTS.get("Save");
}
}
and I have tableField ...
If I add new empty row in this table execStore is called when pressing save button, but if I delete this empty row and press save button nothing is called, button only close form.
How to solve this? I would like to be able to delete empty row.
EDIT :
I figure it out that all rows where only smart fields are filled in, on delete it doesn't detect change. (not only empty rows...)
Problem is that checkSaveNeeded of the form return that nothing was changed in doOk method.
How do you add your row?
You can mark the row as inserted or not. See: addRow(newRow, markAsInserted); on the Table.
You second question is "How does a Table Field computes if the form needs to be stored or not"?
You can implement you custom logic on with execIsSaveNeeded(). See this question on the Scout forum:
https://www.eclipse.org/forums/index.php?t=msg&th=477037&goto=1042295#msg_1042295
Your last point is: when a row has the status ITableHolder.STATUS_NON_CHANGED in an editable table. When the value in a SmartColumn is changed with a SmartField, the status of the row is not changed to ITableHolder.STATUS_UPDATED.
I just tested it and it works as expected.
For row deletion, it depends on how your table field is configured. What is the value of the property isAutoDiscardOnDelete().
The doc here is still valid with Neon: Table > Delete a row from the table
With isAutoDiscardOnDelete() returning true (this is the case if getConfiguredAutoDiscardOnDelete() returns true), when you remove a row in your table field, it is discarded. There is nothing to save because there is no deleted row in the table field (Everything is explained in the wiki section I have mentioned)
If you want to persit a deletion on the server, you should not use discard the row but just delete it. This way you get the information in the FormData and from there you can work with the row status as described here: TableData (again old doc from our wiki, because it works like this since years. This it not new with Neon).
I've just updated my project from jquerymobile 1.0a1 to version 1.0.
I've encountered a problem with dynamic content. Based on an ajax search I populate an unordered list with list items. Previous the following code refreshed the list so that all the styling appeared correctly:
$('#myContent').find("ul").listview();
$('#myContent').find("ul").listview('refresh');
However as of 1.0 this no longer seems to work.
The list appears but the styling is all wrong and the data-theme on all the elements gets ignored.
Has anyone come across a similar issue with updating and come across the solution.
Updating lists If you add items to a listview, you'll need to call the refresh() method on it to update the styles and create
any nested lists that are added. For example:
$('#mylist').listview('refresh');
Note that the refresh() method only affects new nodes appended to a
list. This is done for performance reasons. Any list items already
enhanced will be ignored by the refresh process. This means that if
you change the contents or attributes on an already enhanced list
item, these won't be reflected. If you want a list item to be updated,
replace it with fresh markup before calling refresh.
http://jquerymobile.com/demos/1.0/docs/lists/docs-lists.html
if #myContent is the listview you can do this:
$('#myContent').listview('refresh');
if #myContent is the page you can do something like this:
$('#myContent').trigger('create');
Create vs. refresh: An important distinction Note that there is an important difference between the create event and refresh method
that some widgets have. The create event is suited for enhancing raw
markup that contains one or more widgets. The refresh method should be
used on existing (already enhanced) widgets that have been manipulated
programmatically and need the UI be updated to match.
For example, if you had a page where you dynamically appended a new
unordered list with data-role=listview attribute after page creation,
triggering create on a parent element of that list would transform it
into a listview styled widget. If more list items were then
programmatically added, calling the listview’s refresh method would
update just those new list items to the enhanced state and leave the
existing list items untouched.
http://jquerymobile.com/demos/1.0/docs/pages/page-scripting.html
What you want can be achieved by replacing your 2 lines of code with the following:
$('#myContent ul').listview('create');
Hope this helps...
I've had this issue. The reason you are getting things all messed up is you are initalizing and refreshing the element multiple times. I noticed I had 2 different functions running that would call .listview('refresh') on the same element. After I took one out the themes and data went back to looking normal. Also are you getting any JS errors?
EDIT:
To be more specific you are calling .listview() somewhere in your code 2 times which is initializing it twice. I would wait to before you page is loaded to run the refresh so you only call it once.
Another thing you could do is check if the element is initialized already or not so you don't do it twice. Just check the element or in some cases the parent to see if the class ui-listview is present.
var element = $('#myContent').find('ul');
if ($(element).hasClass('ui-listview')) {
//Element is already initialized
$(element).listview('refresh');
} else {
//Element has not been initiliazed
$(element).listview().listview('refresh');
}
Just an FYI you can chain those events to look like $('#myContent').find('ul').listview().listview('refresh');
It cand be achived through.
$('#myContent').listview('refresh');
The below snippet shows you to load data from xml and dynamically create a list view.
function loadData()
{
$.ajax({
url:"BirthdayInvitations.xml",
dataType: "xml",
success: function(xml)
{
$(xml).find("event").each(function()
{
$("#mymenu").append('<li>' + this.textContent + ' </li>');
});
$("#mymenu").listview('refresh');
}
});
}
See if this is related to ur question http://www.amitpatil.me/demos/jquery-mobile-twitter-app/ and this one also http://www.amitpatil.me/demos/ipad-online-dictionary-app/
In first example i am using listview('refresh'); method and in second example i am using
$(document).page("destroy").page();
I need to get previous value of an entity.
My requirement is like; I have some input fields in an edit page.
1 User can enter some values there and press save button at this time the user should be able to save it.
2 User can enter some values there and press Cancel button at this time the page should be reloaded with whatever values were there before the user start editing the page.
My question is that can entity frame work, help us in getting previous value of an object?
Is self tracking is something related to this?
You mentioned "page" so I guess you are talking about web application. In such case you should simply load entity from the database again because pushing Cancel button will make a new request to your web application. You should use a new context per request so you don't have any previous data or entity to reload - you will run a new query and get last data persisted to database.
What you would want to do is:
myContext.Refresh(RefreshMode.StoreWins, myObject);
This will ask the context to reload the entity removing any changes to the object and replacing the property values from the data store.