Is it possible to somehow change the query variables for query in progress? My idea is that I'm storing number of showed items in route state with variable called pageSize. Now when user opens one item and press back button in browser, I will show him exactly the page he has seen before.But route state persist also while refreshed so I want to listen to onReadyStateChange and if event CACHE_RESTORE_FAILED will be fired I want to change pageSize to initial size. Is it possible to somehow listen to this change on Route level?
After #chris comment adding some code:
Route: you can see how I'm getting pageSize from route state
<Route
path=":username"
prepareParams={(params, { location }) => {
const relayParams = params;
if(location.state && location.state.pageSize) {
relayParams.pageSize = location.state && location.state.pageSize;
}
return relayParams;
}}
component={ProductList}
queries={UserQuery}
/>
It's not needed to show any ProductList code, for now it's just rendering of connection. The idea is simple, you open product list page, click on show more few times, and pageSize number is incremented from 20 to 100. User then click on product number 99, i show him product, he click back and he sees who he has seen before. That's great, route state remembered number of times. But after user click refresh in browser, route state is also persisted, so I'm doing query to fetch first 100 products and that's too much. I want to listen to events and if products are not found in local memory ( env has been switched or page refreshed) I want to update variables to fetch only first 20.
Related
I believe I have found a bug in the Vaadin Grid that can be replicated with the code below.
I would like to save the grid's sorting order whenever it's changed and then restore it when the grid is loaded. The main issue is that the GridSortOrder list just keeps incrementing in size for the event in the sort listener rather than replacing the sortorder list. I believe this is a bug within Vaadin 14-20 because it only happens if I call setColumnOrder() in the reset method below (removing that call it works as expected). In other words calling setColumnOrder() seems to add the list of GridSortOrder to the event in the sort listener when it should be replacing it. This is actually also true if you do grid.getSortOrder() in the listener, meaning it's not just the event but also the grid that is compromised.
This can be replicated consistently with the code below. You will first need to change the sort order of Description column by clicking on the column header. Then just click on Reset button 5-10 times. Once this is done click on the Description column header to change the sort order one more time. The System.out for the listener will show a size of a list of 20 GridSortOrder instead of the expected 2 GridSortOrder. There will be replications of columns over and over.
Grid<Car> grid = new Grid<>();
grid.addColumn(Car::getName)
.setSortable(true)
.setComparator(Car::getName)
.setKey("Name")
.setHeader("Name");
grid.addColumn(Car::getPrice)
.setSortable(true)
.setComparator(Car::getPrice)
.setKey("Price")
.setHeader("Price");
grid.addColumn(Car::getDescription)
.setSortable(true)
.setComparator(Car::getDescription)
.setKey("Description")
.setHeader("Description");
grid.setItems(listOfCars);
grid.setColumnReorderingAllowed(true);
grid.setMultiSort(true);
grid.addSortListener(event -> {
System.out.println("Event: " + event.getSortOrder().size() + " : " + event.isFromClient());
System.out.println("Grid: " + grid.getSortOrder().size() + " : " + event.isFromClient());
});
defaultSort(grid);
Button resetButton = new Button("Reset", click -> {
System.out.println("Reset: " + grid.getSortOrder().size());
defaultSort(grid);
grid.setColumnOrder(
grid.getColumnByKey("Name"),
grid.getColumnByKey("Price"),
grid.getColumnByKey("Description"));
});
add(grid, resetButton);
private void defaultSort(Grid grid) {
grid.sort(List.of(
new GridSortOrder<>(grid.getColumnByKey("Name"), SortDirection.ASCENDING),
new GridSortOrder<>(grid.getColumnByKey("Price"), SortDirection.ASCENDING)
));
}
If I remove grid.setColumnOrder() from the above then the List<GridSortOrder> works as expected and is two in the event listener. What's especially interesting is that event.getSortOrder().size() will increase by 2 every time the resetButton is clicked (but you'll only see it in the sort listener). It doesn't matter if the setColumnOrder() is before or after the call to defaultSort().
With that in mind if you debug grid.setColumnOrder() it seems to call updateClientSideSorterIndicators(sortOrder) which is what I believe is the cause and is where it's being added to the GridSortOrder list. That being said I'm not sure how to proceed from here so that I can reset the grid's setting when clicking on the Reset button.
FYI: This is an issue for me because I'm trying to save the state of the Grid to the database so that when the user reloads the screen (a very complex one) all their grid settings including the sorting order, the column order, and so on are preserved. However with this bug it's impossible to save the sorting order.
PS: This seems to be true in both Vaadin 14 and Vaadin 20.
I have a ListView Builder in the first Page, which receives content(items) from the Second Page. When I hit submit button in Second Page, I use:
Navigator.of(context).pop
Which takes me back to First Screen.
The problem is that it is not updating the item created in the list unless i restart the app.
I have tried:
1) Calling an instance of First Page and using:
firstPageinstance.setState((){});
2) I have also tried to call a function from the First Page class, which invokes setState:
firstPageinstance.funtionWhichCallsetStateinFirstageClass();
But none of this works. The list is updated only when I Restart the App.
P.S. The list items are saved and called from an SQLite database. Also, Let me know if you need more details.
When navigating to your SecondPage await the result like this:
bool isUpdated = await Navigator.push(context, MaterialPageRoute(builder: (context) => SecondPage()),)
if(isUpdated) // do your list update logic here
When going back to FirstPage(tap on submit button), send the expected value such as:
Navigator.pop(context, true);
Helpful read: https://flutter.dev/docs/cookbook/navigation/returning-data
I have the following fragment in a web component:
<div id="mycodes">
<template iterate='code in codeList'>
{{code}}
</template>
</div>
And in a Dart file, codeList is populated when the user clicks on a button:
void onMyButtonClick(Event event) {
HttpRequest.getString('http://getData').then((response) {
mylist = json.parse(response);
for(var code in mylist){
codeList.add(code['c']);
}
}
The problem is that I don't see data on first click. I need to click the button twice to see data.
But if I fill codeList manually (not from network data) as shown below, then I see the data on first click:
void onMyButtonClick(Event event) {
codeList.add("data 1");
codeList.add("data 2");
}
}
I need the template to iterate after the network data is available. It appears that event loop has already done its job of painting a page before the network data becomes available through future object.
Is there a way to refresh the page after model is updated in dart?
The reason your codeList currently populates if you add it with the on-click event is because the current web_ui has 'watchers' which automatically are called when an event happens. You then populate the list synchronously. However one of the downfalls of watchers is exactly your use case, when the data is updated asynchronously then the watchers don't reflect changes in time.
As a result the watchers are being phased out and replaced with observables. Observables allow us to flag a variable to be watched for reassignment and when that happens it will cause the view to change. For example:
#observable int x = 0;
// ...
x = 1;
When the x = 1 is called later in the code it automatically triggers the views to update. This leaves us with one problem however. When you are adding to a list, you are not reassigning the value itself. As such, observables also offer a function to convert a list to an observable list (this also works for maps).
For instance if you changed your declaration of codeList to something like the following, then when you add to the list later it will update accordingly.
var codeList = toObservable([]); // Assuming it starts with an empty list
// or
var codeList = toObservable(_startCodeList); // if you already have a list
Also see the Dart Tutorial: Target 7 for more information on using #observable and toObservable.
For more in-depth information, check out the article on Observables and Data Binding
You need to mark the fields you want WebUi to monitor with the #observable annotation. Otherwise you only get the initial value not any subsequent updates.
You can do this either directly on the object declaration or you can make the entire class as observable and all its fields will then be observed.
For an example see http://www.dartlang.org/docs/tutorials/custom-elements/#using-two-way-data-binding
I have two g:textfields
in the first one I should write a number lets say 12 and in the g:textfield next to it it should load the predetermined name for number 12.
The first one is named 'shipper' and the other 'shipperName'
Whenever I write the code 12 in the 'shipper' txtfield, it should return the name of the shipper in the 'shipperName' box.
Thanks in advance!
Examples:
If I write the number 12 it should return USPS
http://i53.tinypic.com/2i90mc.jpg
And every number should have a different 'shipperName'
Thanks again!
That's quite easy if you'll use jQuery. Check out the event handlers ("blur" is the one you want which occurs when the user leaves the numerical box).
For example:
$("#shipper").blur(function() {
$("#shipperName").load(
"${createLink(controller: 'shipper', action: 'resolveShipper')}?id=" +
$("#shipper").val()
);
});
The $(this).val() at the end is the value of the input field the user just left.
And the "ShipperController.resolveShipper" action would look something like this:
def resolveShipper = {
render text: Shipper.get(params.id).name, contentType: "text/plain"
}
There are other things you might want to do, like automatically filling in the shipperName field as the user types without leaving the edit field, probably after a delay. However the event handler stays the same, just the event is changing (from "blur" to "change" or something like this)
To relate two strings, it's easiest to use an object to create a dictionary/ map, as shown below;
$('#input1').bind('keyup',function() {
var map = {
"1":"One",
"2":"Fish",
"3":"Bar"
};
$('#input2').val(map[$(this).val()]);
});
You can see this in action here: http://www.jsfiddle.net/dCy6f/
If you want the second value only to update when the user has finished typing into the first input field, change "keyup" to "change".
Morning - I'm having a little problem.
I have an autocomplete extender textbox where a user types in words and suggestions are provide. Should the term be rather generic, a list appears and the user can scroll up or down using the mouse wheel with no problems at all.
However, if the user attempts to click on the scroll bar and scroll through the list, it fires the textchanged event - which I don't want it to do.
This event should only fire once the user has actually selected the appropriate product from the list supplied.
I can set the autopost back of the text file off which has the desired effect but I do require the post back to be performed once the user selects a suggestion.
Does anyone know how I can get around this?
I managed to find a resolution.
Stick this in the page load event:
string contactPostBackFunction = null;
contactPostBackFunction = Page.ClientScript.GetPostBackEventReference(this.tbxProdAC, "", false);
string contactPostBackScript = null;
contactPostBackScript = string.Format("function postBackOnContactSelectedFromDropDown() {0} {1} {2}", "{", contactPostBackFunction, "}");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "contactPostBackScript", contactPostBackScript, true);
And have this in your Autocomplete extender properties:
OnClientItemSelected="postBackOnContactSelectedFromDropDown"