I am trying to use FFImageLoading in a ListView using only XAML and a view model. For each item in the list i have a model and I want to trap when an image fails to load and update a label thats associated with the image in the same model.
<ffimageloading:CachedImage
DownsampleToViewSize="true"
RetryCount="0"
ErrorCommand="{Binding ImageLoadError}"
IsVisible="{Binding HasAttachement}"
Source="{Binding Attachment}">
</ffimageloading:CachedImage>
I thought adding an ErrorCommand handler thats bound in my model would work except the command is being invoked for every instance of my model and not just the instance where the image loading fails
ImageLoadError = new Command((e) =>
{
Debug.WriteLine($"Image load error Text is {Text}");
});
The above command handler is invoked for every instance of my model and not just the instance attached to the failed image.
How can i get notifications of loading errors to only the instance of my model thats associated with the image?
As you can see on the FFImageLoading Wiki/Documentation at the Events section (FFImaleLoading Events) there is an event for 'Errors' on which you can listen to.
Error
Occurs after every image loading error. Returns: Exception
Try to subscribe to this event and it should return only those instances which cannot be loaded.
Related
Trying to add a filter for the list. I have a textbox and an event that does this when the textbox text changes:
this.objectListView1.ModelFilter = TextMatchFilter.Contains(this.objectListView1, filterString.Text);
When I key in a character into the textbox I am getting the following error:
System.ObjectDisposedException: 'The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.'
I am using Entity Framework to get the data for the list view. I fill my data when the form with the listview loads using a method for that.
What is causing the error? How do I correct this?
I'm facing an error while I change the default event representation to Object array in this way:
Configuration configuration = new Configuration();
configuration.getEngineDefaults().getEventMeta().setDefaultEventRepresentation(EventUnderlyingType.OBJECTARRAY);
My events definitions are in create schema way. The epl file get successfully deploy, but when I insert a new Object[] event, an error rise telling that there are no event definition for this event name.
If more details are needed, please, ask for it.
After few tests, I can say that it's necessary to define every event type when the default event representation is set to object array.
We have a custom tag similar to g:set which sets the current user into PageScope <n:currentUser var=”foobar”> It works great until we have a flowaction.
For a flowaction view state, which uses above tag, it will throw Lazy initialization exception “could not initialize proxy - no Session”, even though the user is loaded in the same request and set in pagescope.
Doesn’t webflow respect OpenSessionInView ! What’s going wrong here.
What could be the solution other then eager fetching and passing the modal explicitly.
(The tag is in a layout actually, which is applied for the view of the view state)
UPDATE
I just noticed, that even when accessing the the object right after it is loaded, it still gives the same error. So its not PageScope things causing the issue
Inside the tag
User user = User.get(x)
println user.foo.bar gives the same error
It looks like, for flow actions, session isn't kept open at all, and it seems to close right after the operation is complete.
Thanks
I've seen this error before, and not related to the webflow, but using a tag inside a layout. In this case the layout is handled after the session is closed and you need to create a new session manually.
def currentUser = { attrs ->
User.withTransaction {
User user = User.get(x)
}
}
The JIRA have the status won't fix because is not a good practice to make GORM queries inside TagLib's.
preface note: I'm just starting to learn Grails, so I'm sure there are many other problems and room for optimization.
I've got two domains, a parent (Collection) and child (Event), in a one-to-many mapping. I'm trying to code an integration test for the deletion of children. Prior to the code in question, I've successfully created a parent and three children. The point where I'm having problems is getting a single child in preparation to delete it. The first line of my sample code is only there because of my rudimentary attempt to troubleshoot.
// lines 95-100 of my EventIntegrationTests.groovy file
// delete a single event
assertEquals("2nd Event", event2.title) // passes
def foundEvent = Event.get(event2.id) // no apparent problems
assertEquals("2nd Event", foundEvent.title) // FAILS (line #98)
foundEvent.delete()
assertFalse Event.exists(foundEvent.id)
The error message I'm getting is:
Cannot get property 'title' on null object
java.lang.NullPointerException: Cannot get property 'title' on null object
at edu.learninggrails.EventIntegrationTests.testEventsDelete(EventIntegrationTests.groovy:98)
What should my next troubleshooting steps be? (Since the first assertEquals passes, event2 is clearly not null, so at this point I have no idea how to troubleshoot the failure of the second assertEquals.)
This is not evident from the code: did you persist event2 by calling save()? Get will try to retrieve it from the persistent storage (the in-memory database for example) and if the event wasn't saved, the retrieved instance will be null.
If you did save it, did the save go through OK? Calling event.save() will return false if there was something wrong while saving the item (like a validation error). Lastly, you might try calling event.save(flush:true) in case the Hibernate session doesn't handle this case as you might expect (I'm not entirely sure about this one, but it can't hurt to try).
Try to print or inspect the event2.id on line 97 and check if you actually have an id, if so check if you actually get an Event object on line 97.
I dont think you saved the parent and its children successfully. after you save, you should make sure that every object that was persisted has a non null id, in your test.
What you are seeing is you created the event2 with a title, but didnt save it. It passes the first assertion because you created it. When you do the get, null is returned because your save failed.
in general for DAO integration tests i do the following
Setup -- create all objects Ill use in the test.
Save -- assert that all ids on saved objects are NOT null.
Clear the hibernate session -- this is important because if you don't do it, objects can be in the session from the previous operations. In your real world scenario, you are probably going to start with a find, i.e. an empty session. In other words, you are not going to start with anything in the session. If you are you need to adjust this rule so that the session in the test, when you start the actual testing part, is the same as the session of the code in the wild
Load the objects on which you want to operate and do what you need to do.
Let's say I have an AddProductToCartTask with a method Execute().
Now, the task is being called from a Controller. In the Execute method , there
is a check that if not met - the action is not performed.
Let's say the message returned would be: "You do not have enough bonus to buy
this product".
I thought about launching an event when the domain validation fails - but that would mean that in the Controller I have to have all kinds of class variables that need checking in the action (to determine if I need to set an error message, or i need to redirect .. etc)
Instead of this I could have a method on the task : GetErrorMessages(). If empty
return the JSON object if not empty return the Message. Or the method could return an enum that would tell if i need to redirect or set a message or return the object ....
I'm not sure which road to take. Any input would be appreciated. How do you bubble up messages from your domain layer ?
Edit: this is mainly in an AJAX context. Even though I'm not sure it matters as it's an action that it's getting called from somewhere .
I might be misunderstanding your request, but it seems to me like you want a central messages functionality, rather than something specific to the task object. If you leave it in your task, then the task must be kept in scope and "alive" until the AJAX request.
I do something similar, though directly from the Controller.
I have a static class called Messages. It has AddMessage(), GetLastMessage(), and GetAllMessages() methods. Each one, when first called, will check the user's session variable and, if nothing is found, creates and saves a Queue<string>() object. The methods are basically just an interface to the Queue. The Queue is nice because it handles push/pop which automatically removed "viewed" messages.
My controller does:
Messages.AddMessage("Product Saved");
You could potentially do:
Messages.AddMessage(task...GetErrorMessages());
Then, from my View, I have an html helper that checks how many error messages there are and, if any, creates a <ul> with each message as a <li>.
You could just as easily have a GetMessages() controller that returns any messages as a JSON object.
James