I create portlets and there can be many instance of a portlet on a page, so that the functions and dom elements must be identified, AKA they must start with a particular namespace.
so that in some cases, I have to have my JS in a JSP page and cannot move it to a separate file, it is very inconvenient and hard to maintain.
a javascript in a JSP
var validator = new A.FormValidator({
boundingBox: document.orderForm,
validateOnBlur: true,
validateOnInput: false,
rules: {
<portlet:namespace />significanceLevel: {
digits: true
},
<portlet:namespace />languageFrom: {
required: true,
notEqualTo: '#<portlet:namespace />languageTo'
},
<portlet:namespace />languageTo: {
required: true,
notEqualTo: '#<portlet:namespace />languageFrom'
}
}
......
From <portlet:namespace />significanceLevel JSP generates _my_namespace_significanceLevel: .
Even if I pass myNamespace (from a JS in JSP – namespaces resolved on serverside) into a constructor, I cannot create myNamespace + ‘methodName’ in runtime
Namespace is only known on serverSide. So that one JS always has to be in a JSP page so that <portlet:namespace /> is resolved and all other JS objects have it accessible via constructor parameter for instance.
this is one workaround, but it cannot be used in many cases :
window[instance._method] = function() {
instance.fileAddError.apply(instance, arguments);
};
where the name of _method was concatenated from string literals
It is easy to add dynamic properties to objects during runtime:
So you could do something along the lines of: