Wednesday, February 11, 2009

JSTL's expression language and refactoring

Suppose you've got an object of class Person with a getName() method. JSTL's expression language allows you to access this field in your JSP with the following notation - ${person.name} - assuming you've passed the JSP a person variable pointing to an instance of Person. For example, you might use: .

This is a convenient feature, but it has a downside: Suppose your application grows and you now support first and last names. Person.getName() used to return a first name, but now you wish to change the method name to getFirstName(). This is a simple refactoring to do using a modern IDE - the IDE will find every mention of getName() in your code, and change it to getFirstName(). That's not enough, however. Remember to also search through your JSP's for references to this method and change them too.

No comments: