What is the difference between XSP.getElementById
and document.getElementById
? In my tests both seem to return the same value (value stored in field). Which one should be preferred while coding for XPages?
What is the difference between XSP.getElementById
and document.getElementById
? In my tests both seem to return the same value (value stored in field). Which one should be preferred while coding for XPages?
2 Answers
Reset to default 6edited
XSP.getElementById
is the same as dojo.byId
which I believe works in wider range of browsers than document.getElementById
.
Here is the source for XSP.getElementById
:
/**
* Convenience function for retrieving an element given its id in a browser independent manner.
*/
this.getElementById = function x_gbi(elementId){
return dojo.byId(elementId);
}
I guess for better future XPage support it might be a good idea to use XSP.getElementById
(because they might change it) instead of dojo.byId
. I've been using dojo.byId
because it's shorter. document.getElementById
should never be used in XPages because we have dojo.byId
.
update
Starting from Dojo 1.7 the syntax is much more plex:
require(["dojo/dom"], function(dom){
// fetch a node by id="someNode"
var node = dom.byId("someNode");
});
Today my colleque pointed out that Dojo 2 will not support the current simple way of calling dojo.byId
any more. This means that XSP.getElementById
is definitely the way to go and we should start using the new require
based syntax whenever we use Dojo with ND9.
XSP contains code for handling situations with the Notes client (XPiNC) and the web browser. Not using XSP calls in XPiNC may work or may have side effects.
XSP.getElementById works the same way as document.getElementById except it ensures that it works across browsers with the same functionality.
You can read more about how XSP works in the "XPages Portable Command Guide" Page 184 for getElementById.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745155580a4614100.html
评论列表(0条)