Hello everyone, The GWT 1.5 Breaking Changes doc has been updated to mention the change in return values for non-existing attributes in an Element.getAttribute(name) call to make sure this doesn't catch anyone unawares.
GWT 1.5 Breaking Changes: http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=ReleaseNotes_1_5_BreakingChanges In the meantime, Joel has entered Issue #2852 to try to make checking for a specific attribute less ambiguous by introducing an Element.hasAttribute(name) method. This seems like a needed method anyway to complete compliance with the current DOM spec. Issue #2852: http://code.google.com/p/google-web-toolkit/issues/detail?id=2852 However, it's very likely that the reimplementation of the Element.getAttribute(name) method was a bad move on the team's part, so I would suggest we start a new thread on the GWT Contributors group to see whether the new empty string return is a bad decision and whether we should revert to the old contract of returning null for non existing element attributes. Cheers, -Sumit Chandel On Fri, Sep 5, 2008 at 12:54 PM, Ian Bambury <[EMAIL PROTECTED]> wrote: > > > 2008/9/5 Thomas Broyer [EMAIL PROTECTED] > >> >> -- >> Interface Attr >> [...] >> The attribute's effective value is determined as follows: if this >> attribute has been explicitly assigned any value, that value is the >> attribute's effective value; otherwise, if there is a declaration for >> this attribute, and that declaration includes a default value, then >> that default value is the attribute's effective value; otherwise, the >> attribute does not exist on this element in the structure model until >> it has been explicitly added. >> --- >> i.e. an attribute's value cannot be 'null'. >> >> document.createAttribute("foo") for instance creates an attribute with >> an empty-string value, not null. >> > > I don't think anyone is suggesting that an attribute holds a null. > > The question is: what do you return when trying to get the value of an > attribute that doesn't exist? > > <div question="Life, The Universe, and Everything"></div> > > String answer = elem.getAttribute("answer"); > It doesn't hold a value. > It doesn't hold an empty string. > It's not null either because it doesn't exist. > > But in this case, all the browsers I looked at (IE/FF/Safari/Opera/Chrome), > in JavaScript, return a null and now, suddenly, between 1.5.1 and 1.5.2, GWT > decided to go its own way and return an empty string. And break my > programming. (To be fair, I don't think Google made a decision to break my > programs, but on the other hand, there was no consultation with the > user-base of this open-source framework, it just got put in and sent out on > the quiet.) > > The difference between the browsers is when it comes to explicit attributes > - MS has the rule: > > "Returns a string, a number, or a Boolean, defined by > sAttrName. If an explicit attribute doesn't exist, an empty string is > returned. If a custom attribute doesn't exist, null is returned." > > which makes more sense to me as it involves less coding in situations like > className where you are never going to worry about whether it's been set ot > not, just what it is, but will return null if a custome attribute has not > been set or if you make a typo. > > If you *don't* return a null for custom attributes, then people will have > no indication that getAttribute("float") is probably not what they were > after. > > Ian > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
