Categories
discuss

Relative urls for Javascript files

I have some code in a javascript file that needs to send queries back to the server. The question is, how do I find the url for the script that I am in, so I can build a proper request url for ajax.

I.e., the same script is included on /, /help, /whatever, and so on, while it will always need to request from /data.json. Additionally, the same site is run on different servers, where the /-folder might be placed differently. I have means to resolve the relative url where I include the Javascript (ez-publish template), but not within the javascript file itself.

Are there small scripts that will work on all browsers made for this?

Answer

For this I like to put <link> elements in the page’s <head>, containing the URLs to use for requests. They can be generated by your server-side language so they always point to the right view:

<link id="link-action-1" href="${reverse_url ('action_1')}"/>

becomes

<link id="link-action-1" href="/my/web/root/action-1/"/>

and can be retrieved by Javascript with:

document.getElementById ('link-action-1').href;
Categories
discuss

Is EJB still alive?

Do you still use session or entity EJBs in your project? Why?

Answer

EJB3 is a vast improvement over previous versions. It’s still technically the standard server-side implementation toolset for JavaEE and since it now has none of the previous baggage (thanks to annotations and Java Persistence), is quite usable and being deployed as we speak. As one commenter noted, JBoss SEAM is based upon it.

EJB 3 is a viable alternative to Spring, and the two technologies may become more tightly related. this article details that Spring 3.0 will be compatible with EJB Lite (which I’m not sure what that is, exactly) and possibly be part of Java EE 6.

EJB is not going anywhere.

Categories
discuss

XML based website – how to create?

I would like to create an XML-based website. I want to use XML files as datasources since it is a kind of online directory site. Can someone please give me a starting point? Are there any good online resources that I can refer to? I am pretty comfortable with ASP and JavaScript.

Answer

If you cannot or don’t wish to store your data in XHTML format, then XSLT is definitely the way you want to go. By its very definition, it is a transformation language designed to transform data from one format to another. Because this is it’s focus, it provides power, speed and flexibility you won’t find in many other solutions. It will also ensure you output standards compliant (X)HTML as it’s impossible to do otherwise (well, not without deliberately going out of your way to botch it).

MSXML allows you to do XSL transformations for use in Classic ASP – see this page for an example.

ZVON.org is also a great XSLT reference.

Categories
discuss

Is JavaScript object-oriented?

There have been some questions about whether or not JavaScript is an object-oriented language. Even a statement, “just because a language has objects doesn’t make it OO.”

Is JavaScript an object-oriented language?

Answer

IMO (and it is only an opinion) the key characteristic of an object orientated language would be that it would support polymorphism. Pretty much all dynamic languages do that.

The next characteristic would be encapsulation and that is pretty easy to do in Javascript also.

However in the minds of many it is inheritance (specifically implementation inheritance) which would tip the balance as to whether a language qualifies to be called object oriented.

Javascript does provide a fairly easy means to inherit implementation via prototyping but this is at the expense of encapsulation.

So if your criteria for object orientation is the classic threesome of polymorphism, encapsulation and inheritance then Javascript doesn’t pass.

Edit: The supplementary question is raised “how does prototypal inheritance sacrifice encapsulation?” Consider this example of a non-prototypal approach:-

function MyClass() {
    var _value = 1;
    this.getValue = function() { return _value; }
}

The _value attribute is encapsulated, it cannot be modified directly by external code. We might add a mutator to the class to modify it in a way entirely controlled by code that is part of the class. Now consider a prototypal approach to the same class:-

function MyClass() {
  var _value = 1;
}
MyClass.prototype.getValue = function() { return _value; }

Well this is broken. Since the function assigned to getValue is no longer in scope with _value it can’t access it. We would need to promote _value to an attribute of this but that would make it accessable outside of the control of code written for the class, hence encapsulation is broken.

Despite this my vote still remains that Javascript is object oriented. Why? Because given an OOD I can implement it in Javascript.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..