• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting List of Attributes Used By a JSP  RSS feed

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to generate a list of attributes used in a JSP? When I try to reuse a JSP, sometimes it is not clear what attributes have to be set beforehand. And, there doesn't seem to be any mechanism to declare them like method parameters.
 
Praveen Babu
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried,

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I mean is, say when we are refactoring codes, given a JSP page how do we know what attributes the servlet need to set in order to use it? Given a class, we just need to inspect the public methods and their return values/arguments to determine how to use it. From a software engineering perspective, it seems that JSP doesn't facilitate maintanence/reuse. Am I right?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alec Lee:
Given a class, we just need to inspect the public methods and their return values/arguments to determine how to use it.

I see that as a bit upside down.
I would never start with a JSP and ask what objects are avalialble and how do I use them. That, in itself, suggests that too much control is being given to the view. In JSP2.0 a JSP page should be nothing more than a template for displaying data after the real decisions have been made.

That being said, it was easier to look up a bean's javadoc API to see what properties are available when jsp:useBean tags were required.


From a software engineering perspective, it seems that JSP doesn't facilitate maintanence/reuse.


In JSP 2.0 maintenance and reuse are facilitated by pulling nearly everything out of the JSP in the first place.
Also, the introduction of tag files makes it easier to re-use small bits of markup code.

Am I right?

My experience with scriptless JSPs would lead me to say, no.
They result in cleaner, more thought out components that are much easier to maintain.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say we first create a prototype using HTML, then iteratively turn it into working JSP and add controller logic to call it. Then we need to decide what attributes are expected in the JSP first.

But the point is this would sometimes like calling another method by using global variables instead of method parameters. If we misspell the attribute name in controller, no error given and the JSP still work except expression like this ${username} display nothing. In traditional programming language, we already know the problem of global variables and the need to declare variables before using them. But why in JSP we don't have similar facilities?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alec Lee:
But why in JSP we don't have similar facilities?


It doesn't. The scoped variables that a page requires to operate correctly are part of an unwritten contract that any controller that forwards to that page must satisfy.

All too often this contract is left for those writing controllers, if different from those writing the JSP, to figure out for themselves.

A good JSP developer will document the page contract.

For myself, I prefer the page to blow up spectacularly rather than exhibit subtle and incorrect behaviors when the contract is broken, so my pages explicitly test that the contract is met and throw an exception if not.

To make this as painless as possible, I created a "contract tag" that declares the expectations of the page and also serves as the documentation for the page contract.

Some typical usages might be:



and so on.

Any contract that is not met results in an exception that makes it clear that the controller has not met its obligations, thus preventing long debug session trying to figure out what's missing.
[ October 05, 2006: Message edited by: Bear Bibeault ]
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any tools that can generate the "page contract" expected from a JSP page?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
None that I am aware of. In any case, I tend to distrust such "tools". I'd rather have complete control over what's going on with my pages.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!