How to generalize multiple *.jsp which do almost the same thing ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ken_Loh
Posted On:   Friday, February 25, 2005 08:12 AM

I have a Tiles Definition that uses many child JSP files doing the same thing, which is listing elements in their respective Collection. For the 1st child JSP, it contains code like: <% Collection c = (Collection)request.getAttribute("localElements"); %> The 2nd child contains: <% Collection c = (Collection)request.getAttribute("domesticElements"); %> Other children get other collection with different attributes. All the children have the same code of displaying all the elements in the Collection by iteration. It doesn't take an Ein   More>>

I have a Tiles Definition that uses many child JSP files doing the same thing, which is listing elements in their respective Collection.



For the 1st child JSP, it contains code like:

<%

Collection c = (Collection)request.getAttribute("localElements");

%>




The 2nd child contains:

<%

Collection c = (Collection)request.getAttribute("domesticElements");

%>




Other children get other collection with different attributes. All the children have the same code of displaying all the elements in the Collection by iteration.




It doesn't take an Einstein to know that this is not good. A lot of duplicate codes in different JSPs exist just because each child JSPs need to iterate different collections.





Any advice of how I could extract the common codes such that there will be no duplication in the JSPs?

   <<Less

Re: How to generalize multiple *.jsp

Posted By:   Christopher_Koenigsberg  
Posted On:   Saturday, February 26, 2005 09:33 AM

As a start, write a helper class for them to call, with something like, "Collection getMyCollection(request, attributeName)" perhaps?



You could even have the "attributeName" be an attribute that is in the tile definition, so you can define multiple tiles that use the same JSP, but each supply a different value for this attribute.
About | Sitemap | Contact