I have an ArrayList of custom beans. I’d like to use the jstl join function with an ArrayList by calling the toArray method of the ArrayList and then overriding toString on the objects it contains.
It’s been said that there is nothing really stopping me from extending classes to include a “get” for methods/properties that I would like to expose to JSP.
So, for this example:
class MyArrayList extends ArrayList
{
public Object[] getToArray()
{
return this.toArray();
}
}
Good idea?
I’ve been creating classes like this with re-usability in mind which has me wondering: Is there a library in existence that simply extends a lot of core Java classes by aliasing useful methods to have a “get” version so they can be used in JSP?
Of course, this may be another case of me not quite grasping some fundamental concepts with regard to JSP but I see it as pure inconvenience that only bean type classes with the “get” style method names can be used in a JSP page. If so, please feel free to tell me why a library like this is a bad idea. Basically, if a library like I describe doesn’t exist, why not?
As to your concrete functional requirement, you could create a custom EL
join()function which takes aListorCollection.E.g.
Which you register as follows in a
/WEB-INF/functions.tldfile:Which can finally can be used as
Or if you happen to have Apache Commons Lang already in the classpath, just delegate to it instead.
As to your initial question, I would rather not add custom public methods to an custom implementation of an already existing interface and rely on that custom implementation.