Cookie return undefined in GWT - gwt

I have created cookie for user name. Its working fine.
But my problem is:
when i clear cookie and try Cookies.getCookie("uname"); then it will return undefined insted of null.
so how to deal with undefined value ?
I am trying that if uname is not set then goes to else part;
please help me.

Yes, it is like this. Failure by design, please see here
https://code.google.com/p/google-web-toolkit/issues/detail?id=2994
The recommended workaround works:
String val = Cookies.getCookie("uname");
if (val == null || "undefined".equals(val)) {
...
} else {
...
}
But normally it seems to work even without this workaround. In my case I got the 'undefined' on JavaScript level, but in Java code it was sufficient to check for null. The real problem which let crash the code was a few lines later and didn't have anything to do with the getCookie() method. So have a look if you really identified the line with the problem.

Related

Why does calling AutoFake.Provide() wipe out fakes already configured with A.CallTo()?

Why does calling fake.Provide<T>() wipe out fakes already configured with A.CallTo()? Is this a bug?
I'm trying to understand a problem I've run into with Autofac.Extras.FakeItEasy (aka AutoFake). I have a partial solution, but I don't understand why my original code doesn't work. The original code is complicated, so I've spent some time simplifying it for the purposes of this question.
Why does this test fail? (working DotNetFiddle)
public interface IStringService { string GetString(); }
public static void ACallTo_before_Provide()
{
using (var fake = new AutoFake())
{
A.CallTo(() => fake.Resolve<IStringService>().GetString())
.Returns("Test string");
fake.Provide(new StringBuilder());
var stringService = fake.Resolve<IStringService>();
string result = stringService.GetString();
// FAILS. The result should be "Test string",
// but instead it's an empty string.
Console.WriteLine($"ACallTo_before_Provide(): result = \"{result}\"");
}
}
If I swap the order of the calls to fake.Provide<T>() and A.CallTo(), it works:
public static void Provide_before_ACallTo()
{
// Same code as above, but with the calls to
// fake.Provide<T>() and A.CallTo() swapped
using (var fake = new AutoFake())
{
fake.Provide(new StringBuilder());
A.CallTo(() => fake.Resolve<IStringService>().GetString())
.Returns("Test string");
var stringService = fake.Resolve<IStringService>();
string result = stringService.GetString();
// SUCCESS. The result is "Test string" as expected
Console.WriteLine($"Provide_before_ACallTo(): result = \"{result}\"");
}
}
I know what is happening, sort of, but I'm not sure if it's intentional behavior or if it's a bug.
What is happening is, the call to fake.Provide<T>() is causing anything configured with A.CallTo() to be lost. As long as I always call A.CallTo() after fake.Provide<T>(), everything works fine.
But I don't understand why this should be.
I can't find anything in the documentation stating that A.CallTo() cannot be called before Provide<T>().
Likewise, I can't find anything suggesting Provide<T>() cannot be used with A.CallTo().
It seems the order in which you configure unrelated dependencies shouldn't matter.
Is this a bug? Or is this the expected behavior? If this is the expected behavior, can someone explain why it works like this?
It isn't that the Fake's configuration is being changed. In the first test, Resolve is returning different Fakes each time it's called. (Check them for reference equality; I did.)
Provide creates a new scope and pushes it on a stack. The topmost scope is used by Resolve when it finds an object to return. I think this is why you're getting different Fakes in ACallTo_before_Provide.
Is this a bug? Or is this the expected behavior? If this is the expected behavior, can someone explain why it works like this?
It's not clear to me. I'm not an Autofac user, and don't understand why an additional scope is introduced by Provide. The stacked scope behaviour was introduced in PR 18. Perhaps the author can explain why.
In the meantime, if possible, I'd Provide all you need to before Resolveing, if you can manage it.

mshtml fireevent onchange not firing

I am unable to fire an "onchange" event in mshtml. Can you please tell me what I am doing wrong here.
HTMLSelectElement element = (HTMLSelectElement)this.HTMLDocument.all.item(controlId, 0);
IHTMLElement e = element as IHTMLElement;
IHTMLDocument4 doc = e.document as IHTMLDocument4;
object dummy = null;
object eventObj = doc.CreateEventObject(ref dummy);
HTMLSelectElementClass se = element as HTMLSelectElementClass;
se.FireEvent("onchange", ref eventObj);
I am getting variable "se" as null. I got this piece of code from another link http://www.itwriting.com/phorum/read.php?3,1507
Can anyone help me with this.
Thanks,
Sam
Runtime Callable Wrapper objects generated by COM calls like HTMLDocument.all.item can translate interface casting to QueryInterface calls. But the RCW does not know how to convert to a managed class like HTMLSelectElementClass, thus it returns null.
Instead of casting to HTMLSelectElementClass, cast to IHTMLElement3 to call fireEvent.
By the way, your code does not work in IE11 mode as document.all is deprecated. Use IHTMLDocument3::getElementById instead.
I had tried all those which Sheng mentioned but didn't work.
This issue was solved by injecting javascript code for "onchange" and executing it. It worked.

Issue with eclipse: Potential null pointed analysis

May be, This has been discussed many times. But, I am not clear on how #javax.annotation.nullable and notnull works in Eclipse. I have the below code in eclipse.
if(null != getApplicant()){
name = getApplicant().getName(); //Potential null pointer access
}
Wherein, getApplication() is annotated with #Nullable.
In the above code, I have verified against null before accessing it. But, still I get error here by compiler. The same code works fine Intellij. (Most of the developers in my team use this :().
Kindly tell me how can I get this #javax.annotation.Nullable and #javax.annotation.Notnull worked in eclipse in similar way to Intellij. I dont want to change my IDE just for this different behavior.
There's no assurance to the compiler that calling getApplication() the second time returns a non-null result as it did the first time. Store it in a local for the test and then use that within the if block.
Eclipse warns you, that the second method access could potentially return null. Example code to reproduce nullpointer:
public class A {
int numberCalls;
Applicant getApplicant() {
if (numberCalls++ > 3)
return null;
else
return new Applicant();
}
}
I would suggest to implement your call like this:
Applicant applicant = getApplicant();
if(null != applicant){
name = applicant.getName(); //not anymore Potential null pointer access
}

Query not fetching results in Grails/MongoDB App

I am developing an app in grails and mongodb. I am facing a very weird error. My controller class is as follows:
def report()
{
def website ="http://www.downloadaudiosongs.com/?dir&page=all"
def res = Resource.findAllByWebsite(website)
int noOfResources = res.size()
println noOfResources
}
This shows me noOfResources as 0.
This same findAllByWebsite query works in mongoDB and shows me the appropriate records.
db.resource.find({ "website": "http://www.downloadaudiosongs.com/?dir&page=all"})
But in my grails app, it doesn't fetch any records for this value of website where as for some other value, it does. I tried grails clean but nothing helped. Can anyone tell me why this might be happening?
Edit: So I think I know what is causing the issue. The ? symbol in the url is doing it because db.resource.find works for all other urls except the ones with ? and special characters. Please correct me if my understanding is flawed.
Thanks in advance.

Editor.isDirty() broken?

The Editor.isDirty() does not seem to be working correctly. In our application we check the Editor.isDirty() flag. When it evaluates to true we need to move forward with some actions. If nothing has changed we don't want to waste processor time evaluating data that hasn't changed. In our case once the content is updated once isDirty() always evaluates to true. Even when nothing has changed.
The Editor.isDirty() function seems pretty simple:
isDirty : function() {
var self = this;
return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
}
The key seems to be the startContent property. That's what TinyMCE uses to determine a change has occured. Therefore I would expect this property to be updated when save() is called on the Editor. Looking through the code shows this does not happen. In fact startContent does is not reset anywhere which would support it's use here. Has anyone else seen this behavior, or am I using the Editor object incorrectly?
sidenote: TinyMCE version 3.5.7.